Difference: LaTeX (32 vs. 33)

Revision 332014-03-01 - KevinLeytonBrown

Line: 1 to 1
 
META TOPICPARENT name="EmpiricalAlgorithmics"

LaTeX tips and tricks

This page is part of the EmpiricalAlgorithmics web.

Space squeezing

%% add a line to a page
\enlargethispage{\baselineskip}

%% keep figures from going onto a page by themselves
\renewcommand{\topfraction}{0.9}
\renewcommand{\textfraction}{0.07}
\renewcommand{\floatpagefraction}{0.9}
\renewcommand{\dbltopfraction}{0.9}		% for double-column styles
\renewcommand{\dblfloatpagefraction}{0.7}	% for double-column styles

% other figure trickery
\floatsep: space left between floats (12.0pt plus 2.0pt minus 2.0pt)
\textfloatsep: space between last top float or first bottom float and the text (20.0pt plus 2.0pt minus 4.0pt)
\intextsep : space left on top and bottom of an in-text float (12.0pt plus 2.0pt minus 2.0pt)
\dbltextfloatsep is \textfloatsep for 2 column output (20.0pt plus 2.0pt minus 4.0pt).
\dblfloatsep is \floatsep for 2 column output (12.0pt plus 2.0pt minus 2.0pt).
\abovecaptionskip: space above caption (10.0pt).
\belowcaptionskip: space below caption (0.0pt).


%% make lists small
\newcommand{\denselist}{\itemsep 0pt\topsep-6pt\partopsep-6pt}

%% make section headings take up less space ("medium" can be replaced by "tiny", "small" or "big"--tiny is the normal font)
\usepackage[medium,compact]{titlesec}

%% an alternative, which might look better and is more adjustable
%% the negative number in beforeskip means that the indent in the following paragraph is suppressed
%% a negative afterskip means that there's no linebreak after the heading
\makeatletter
\renewcommand\section{\@startsection
  {section}{1}{0mm}%name, level, indent
  {-2.5ex \@plus -1ex \@minus -.2ex}% beforeskip
  {1ex \@plus.2ex}%				afterskip
  {\normalfont\large\bfseries}}% style
\renewcommand\subsection{\@startsection
  {subsection}{2}{0mm}%name, level, indent
  {-2.25ex\@plus -1ex \@minus -.2ex}%beforeskip
  {.8ex \@plus .2ex}%afterskip
  {\normalfont\normalsize\bfseries}}% style
\makeatother

%% a trick that makes the title take up less space for many style files (but not article)
\addtolength{\titlebox}{-1.8cm}

%% for article, and maybe other styles, to make the title take up less space you can add negative
%% vspace directly to the title, author and date commands.  Here's one configuration that worked for me:
\title{\vspace{-2.5em} title...}
\author{\vspace{-.5em} author...}
\date{\vspace{-1.25em}}

%% print a diagram showing the names of all constants related to margins etc.
\usepackage{layout}
\layout

%% make a paragraph one line shorter without deleting any words!  Put the following at the beginning, the wrap the paragraph in {}
\looseness=-1

%% make the whole document shorter--this one is very powerful.  Experiment with the number; 0.97 will do a lot and looks OK
\renewcommand{\baselinestretch}{0.97}

% To densify sections
  \let\oldsection=\section
  \renewcommand{\section}[1]{%
	 \vspace{-.5em}\oldsection{#1}\vspace{-.25em}%
  }%
  \let\oldsubsection=\subsection
  \renewcommand{\subsection}[1]{%
	 \vspace{-.5em}\oldsubsection{#1}\vspace{-.25em}%
  }%

% To squeeze space in the bibliography:
  \let\oldthebibliography=\thebibliography
  \let\endoldthebibliography=\endthebibliography
  \renewenvironment{thebibliography}[1]{%
	 \begin{oldthebibliography}{#1}%
		\setlength{\parskip}{0ex}%
		\setlength{\itemsep}{0ex}%
  }%
  {%
	 \end{oldthebibliography}%
  }


%% densify spacing in bibliographies
\newcommand{\bibfix}{%	 PUT \bibfix in file.bbl after first line
	 \setlength{\parsep}{\parskip}%
	 \setlength{\itemsep}{0cm}%
	 \setlength{\topsep}{\parskip}%
	 \setlength{\parskip}{0cm}%
	 \setlength{\partopsep}{0cm}%
	 \setlength{\listparindent}{\parindent}%
	 \setlength{\labelwidth}{10pt}%
	 \setlength{\labelsep}{0pt}%
	 \setlength{\leftskip}{0pt}%
	 \setlength{\leftmargin}{0pt}%
}

%% change margins
% the best way:
\usepackage[margin=1in]{geometry}

%old-school:
\setlength{\textwidth}{7in}
\setlength{\textheight}{8.75in}
\setlength{\oddsidemargin}{-0.25in}
\setlength{\evensidemargin}{-0.25in}
\setlength{\headsep}{10pt}

%% make vertical rubber space
\vfill % this makes a pre-defined amount of rubber space. It's equivalent to \vspace\fill
\vskip 10pt % this makes a fixed amount.  It's a TeX command, so no curly braces.

Fonts and symbols

Find that latex symbol by drawing it.

% compact font that is good for tables; can also use {9pt}{8pt} depending on style file
\fontfamily{cmss}\fontseries{uc}
\fontsize{10pt}{9pt}
\selectfont

% relative font sizes
\usepackage{relsize}
{\smaller ... }
% another option, allows nonstandard sizes
\usepackage{scalefont}
{\scalefont{1.2} ... }

%% get an actual tilde (~) in latex without resorting to $\sim$:
\textasciitilde

%% lowercase script letters
\DeclareFontFamily{OT1}{pzc}{}
\DeclareFontShape{OT1}{pzc}{m}{it}{<-> s * [1.200] pzcmi7t}{}
\DeclareMathAlphabet{\mathscr}{OT1}{pzc}{m}{it}

%% superimpose one symbol on another to make a new symbol
%% the arguments are x and y alignment, in em (pos or neg)
%% here I superimpose a square with a capital V and a small v
%% largesquare comes from the mnsymbol package; boxempty comes from stmaryrd
\usepackage{slashed}
\usepackage{mnsymbol}
\usepackage{stmaryrd}
\declareslashed{}{\largesquare}{-.01}{0.005}{V}
\declareslashed{}{\boxempty}{.06}{-.04}{\mathscr{v}}
\newcommand{\boxV}{\slashed{V}}
\newcommand{\boxv}{\slashed{\mathscr{v}}}

% get an inline equation to be displayed like an {equation} (e.g., subscripts under \sum)
$\displaystyle \sum_i x^i$
% the alternative, to get a displaymath equation to display like an inline one (perhaps to save space):
\[\textstyle \sum_i x^i\]

Footnotes

% repeat the same footnote multiple times
one\footnotemark[\arabic{footnote}]
two\footnotemark[\arabic{footnote}]
\footnotetext{Whatever}

% another way of doing the same thing, which creates different-numbered footnotes if there's a page break
\usepackage{fixfoot}
\DeclareFixedFootnote{\whatever}{Whatever.}
one\whatever
two\whatever

% Make footnotes one-per-page
\usepackage{perpage} 
\MakePerPage{footnote}

% number footnotes with symbols
\makeatletter
\def\@makefnmark{\@textsuperscript{\normalfont\fnsymbol{footnote}}}%
\makeatother

% symbol footnotes with a special command that can be interspersed with other footnotes
% use: \symbolfootnote[1]{footnote} to get an *, 2 = dagger, 3=ddag; etc. 0 is unnumbered footnote.
\long\def\symbolfootnote[#1]#2{\begingroup\def\thefootnote{\fnsymbol{footnote}}\footnote[#1]{#2}\endgroup} 

Tables

Added:
>
>
Force LaTeX not to reposition tables:

In the preamble:

\usepackage{float}
\restylefloat{table}

Then for each table you can use the H placement option (e.g. \begin{table}[H]) to make sure it doesn't get repositioned. Don't use "h".

 
\usepackage{booktabs}

\begin{table}
\begin{tabular}{ccc}
\toprule
\textbf{a} & \textbf{b} & \textbf{c} \\ 
\midrule
1 & 2 & 3 \\ 
\bottomrule
\end{tabular}
\end{table}

A good reference for how to make beautiful tables, particularly when they're complicated and hierarchical: http://www.ece.cmu.edu/~pueschel/teaching/guides/guide-tables.pdf

To place whitespace between rows (better than hlines):

\newcommand{\interrowspace}{.6em} \addlinespace[\interrowspace]

Misc trickery

% place a note for editing
\newcommand{\note}[1]{}
\providecommand{\note}[1]{~\\\frame{\begin{minipage}[c]{\textwidth}\vspace{2pt}\center{#1}\vspace{2pt}\end{minipage}}\vspace{3pt}\\}

% version for 2-column documents
\renewcommand{\note}[1]{~\\\frame{\begin{minipage}[c]{\columnwidth}\vspace{2pt}\center{#1}\vspace{2pt}\end{minipage}}\vspace{3pt}\\}

% Sometimes the footnotes don't appear at the bottom of the page. Than you have to use 
\usepackage[bottom]{footmisc}

% get an extra line on one page
\enlargethispage{\baselineskip}

% argmax and argmin
\newcommand{\argmax}{\mathop{\arg\max}}
\newcommand{\argmin}{\mathop{\arg\min}}


% best bibliography style for APA-style citations
\usepackage{apacite}
\renewcommand{\APACrefbtitle}[2]{\Bem{#1}} % this prevents booktitle field in "inproceedings" citations going into lowercase
\bibliographystyle{apacite}

% bibliography that looks like [22], but with \emcite capabilities too
\usepackage{natbib}
\bibpunct{[}{]}{;}{n}{,}{,}
\bibliographystyle{plain}

% keep hyperref from looking ugly (fuller version with metadata for PDF in mas.tex)
\hypersetup{pdftex,
	 backref=true,
	 pagebackref=true, % backrefs in bib. Apparently doesn't work with mlapa
	 colorlinks=false, % if this is true, the text is colored instead
	 pdfborder=0 0 0,  % no colored border around links either
	 pdfdisplaydoctitle=true
}

% in beamer, make a block without a title
\begin{block}{} block text \end{block}

% in beamer, have nonugly math fonts
\usefonttheme[onlymath]{serif}

% reset the theorem counter to a previously referenced value
% e.g., for repeating a theorem in an appendix
% of course, also works with lemma, corollary, etc.
\usepackage{refcount}
\newcounter{thmbackup}
\setcounter{thmbackup}{\value{theorem}}
\setcounterref{theorem}{thm:name}
\addtocounter{theorem}{-1}
\begin{theorem}...[[repeated theorem]]...\end{theorem}
\setcounter{theorem}{\value{thmbackup}}

%% Define a new style for URLs that will use a smaller font.
%% use a different one for footnotes (requires manual switching)
\makeatletter
\def\url@newstyle{%
  \@ifundefined{selectfont}{\def\UrlFont{\sf}}{\def\UrlFont{\small\ttfamily}}}
\def\url@newFNstyle{%
  \@ifundefined{selectfont}{\def\UrlFont{\sf}}{\def\UrlFont{\scriptsize\ttfamily}}}
\makeatother
\urlstyle{new}
%% then in a footnote: \footnote{\urlstyle{newFN}\url{http://whatever.com}\urlstyle{new} is worth checking out.}


%create a ref that takes the value of a counter. Use this to make a forward reference to a counter's value
%
%at the top:
\newcounter{countsomething}
This is my counter's final value: \ref{numsomething}.
%
%throughout, or hidden inside a repeatedly used macro:
\addtocounter{countsomething}{1}
%
%at the end:
\makeatletter%
 \immediate\write\@mainaux{%
%use the following version if hyperref is being used
		  \string\newlabel{numsomething}{{\arabic{countsomething}}{\arabic{page}}{}{}{}}%
%use the following version if hyperref is not being used
		  \string\newlabel{numsomething}{{\arabic{countsomething}}{\arabic{page}}}%
}%
\makeatother%

Spacing displays

  • Spacing in displays. Usually it's best to leave the spacing up to TeX. However, if explicit horizontal spacing is needed (for example, to set an expression like (n \to \infty) apart from the rest of the display, or to separate two equations on the same line), \quad in most cases generates the right amount of space. Don't try to create spacing with a bunch of explicit spaces ("\ "); the spacing generated in this way is usually not optimal, and the explicit spaces will likely have to be removed (and possibly replaced by \quad) when the paper is typeset at the publisher's end.
  • Avoid blank lines before or after a display, unless you really want to start a new paragraph: It is tempting to surround displayed math material by blank lines in the source file, to make them stand out and easier to locate. However, this is usually wrong, since blank lines are interpreted as paragraph breaks, may generate some additional vertical spacing and cause the next line of text to be indented - something you usually don't want. If you want to set off displays in your source file, do so by inserting a line with comment symbols, such as %%%%% equation 3.1 %%%%%%%%%%%%%% before and/or after the display.
  • Correcting underful vboxes and bad page breaks. By default, TeX does not break pages inside display environments such as align. If a paper has many multiline formulas, this may cause "underful vboxes", which can look very poor if the badness (reported by TeX in the log file) is a few thousand. One way to remedy this is to put the command \allowdisplaybreaks in the preamble. However, this may cause some poor pagebreaks which may have to be fixed. A compromise solution is to use \allowdisplaybreaks locally, on the individual displays that cause problems: {\allowdisplaybreaks \begin{align} ... \end{align} }. The best solution is to prevent this problem by avoiding excessively long displays (say, with five or more lines). It is often not hard to break up a very long display into two, for example by inserting a phrase like "By the Cauchy-Schwarz inequality, the last expression is at most" in the middle of the overlong display, followed by the remaining lines of the display.
  • Multiline subscripts on sums or integrals. Use the \substack{...} command, which works much like the \sb ... \endsb pair in amstex. It is much easier to use, and produces better looking output than an array environment or a construct using \atop (derived from plain tex).

Useful links

-- Main.kevinlb - 13 Apr 2005

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback