Things I Frequently Forget (TIFF)

Latex


Latex is great, but sometimes it seems almost impossible to do something really simple. Here is a bunch of tips that I have collected off the web and have found useful. I do not claim these to be my own, and acknowledgements are given at the bottom of the page.


How to adjust the spacing between the references inthe bibliography?

LaTeX normally inserts extra space between each item in the bibliography. A quick but ugly way of removing this space is by setting the thebibliography environment:

\begin{thebibliography}
\setlength{\itemsep}{-2mm} 


This is not practical if bibTeX is used, as the thebibliography environment will be in the .bbl file, which is overwritten each time bibTeX is run. A better solution is a redefinition of thebibliography. A modification of the the original definition, just include the bibspacing.sty package to set the spacing to zero. Another spacing may be selected by setting the \bibspacing length. To set the spacing to one line, use:

\usepackage{bibspacing}
\setlength{\bibspacing}{\baselineskip}



How to adjust the spacing between items in the itemize and enumerate environments?

Add the following to the preamble:

\newcommand{\squishlist}{ 
   \begin{list}{$\bullet$}
    { \setlength{\itemsep}{0pt}      \setlength{\parsep}{3pt} 
      \setlength{\topsep}{3pt}       \setlength{\partopsep}{0pt}
      \setlength{\leftmargin}{1.5em} \setlength{\labelwidth}{1em}
      \setlength{\labelsep}{0.5em} } }

\newcommand{\squishend}{
    \end{list}  } 


This command can be used in a similar way to the itemize envionment:

\squishlist    %% \begin{itemize}
\item First item
\item Second item
\squishend     %% \end{itemize}



How to put the figure and caption side by side?

Normally the caption goes below or above the figure, but you may want it to the left or the right instead. The minipage environment is useful. The following example puts the figure on the left side using 58% of the with, and the caption on the rigth using 38% of the with. The remaining 4% of the page width ends up separating the two due to the \hfill command.

\begin{figure}
  \begin{center}
    \begin{minipage}[t]{0.58\linewidth}
      \epsfig{file=somefile.ps, width=\linewidth}
    \end{minipage}\hfill
    \begin{minipage}[t]{0.38\linewidth}
      \caption{This is the caption.\label{fig:rawss}}
    \end{minipage}
  \end{center}
\end{figure}


Note the placement of the \label command, it must appear inside the \caption command, or after it but still inside the minipage environment. Otherwise references to the figure will be wrong. The vertical alignment of the figure and the caption may be troublesome, you may have to put the figure inside a \raisebox command.

\raisebox{2cm}{\epsfig{file=somefile.ps, width=\linewidth}}


Or change the [t] optional argument to the minipage environments to [c] or [b]. Experiment!


How to align the decimal points in a table?

In scientific tables it is often desirable to align the columns on a decimal point. This can be done using the @ col specifier and breaking the number into the integral part in a right-justified column and the fractional part in a left-justified column:

\begin{tabular}{r@{.}l}
3&14159\\
16&2\\
123$456\\
\end{tabular}


Note that the decimal point is replaced by the column separator, & and that the @ suppresses the intercolumn space


Using counters

Latex has several predefined counters used to number various environments, for example:

equation   section   page   figure
table      chapter   part   footnote


The counters can be accessed by prefixing the counter name with \the, so for example \thesection will give the current section number. New counters can be defined using the following:

\newcounter{mycounter}[oldcounter]


The oldcounter argument is optional but, if defined, the new counter will be reset whenever the oldcounter is incremented. If you define a new environment, then the assocated counter can be incremented automatically by adding \refstepcounter{mycounter} to the environment definition. Counters can also be manipulated using \setcounter{mycounter}{8} and \addtocounter{mycounter}{-1}

Counters can be fomatted using \format{mycounter} , where \format is one of \arabic (1, 2, 3,...) \alph (a, b, c,...) \Alph (A, B, C,...) \roman (i, ii, iii,...) \Roman (I, II, III,...) \fnsymbol (∗, †, ‡, §, ¶,... )


Acknowledgements

Most of these tips are not my own, so thanks goes to the following: Jakob Schiøtz and Gurmeet Singh Manku