LaTeXTricks

 Chair for Computer Aided Medical Procedures & Augmented Reality Lehrstuhl für Informatikanwendungen in der Medizin & Augmented Reality

# LaTeXTricks

## Adjusting space between references in the bibliography.

LaTeX normally inserts extra space between each item in the bibliography. A quick but ugly way of removing this space is by setting \itemsep to -2mm (experiment to find the right length) inside 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. I have cut out and modified 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}

NOTE: If you use the natbib package, you should use natbibspacing.sty instead, and be sure to load it after natbib:
\usepackage{natbib,natbibspacing}


## Adjusting spacings etc. in itemize, enumerate and description environments.

The standard listmaking environments are defined as special versions of the list environment. The list environment contains a large number of adjustable parameters, setting the margins, spacing between items etc. etc. Some of these, such as \itemsep can be set immediately after the \begin command:

\begin{itemize}\addtolength{\itemsep}{-0.5\baselineskip}

Others, such as \topsep, cannot be adjusted in this way as it is used inside the \begin statement. Anyway, in the spirit of LaTeX these spacings should be adjustable in a global way. Solution: The tweaklist.sty package redefines the itemize, enumerate and description packages, so that all parameters can be adjusted. This was done by copying the original definitions, and adding "hook commands" that are executed when entering the environment. The hook commands are initially empty, but can be redefined with \renewcommand.

Example: to set \topsep and \itemsep to 0 in the enumerate environment, use:

\usepackage{tweaklist}
\renewcommand{\enumhook}{\setlength{\topsep}{0pt}%
\setlength{\itemsep}{0pt}}

The following hook commands are defined: enumhook for the enumerate environment, itemhook for the itemize environment, and descripthook for the description environment. LaTeX keeps track of nested enumerate and itemize environments. If you only want to modify a specific nesting level, you should not use enumhook or itemhook. Special hooks are defined that are only called at the specific level. For the enumerate environment they are enumhooki, enumhookii, enumhookiii, and enumhookiv. For the itemize environment they are itemhooki, itemhookii, itemhookiii, and itemhookiv. The level-specific hooks are called after the global hook, so they can redefine a setting in the global hook. As LaTeX does not keep track of the nesting level of description environments, there are no level-specific hooks for that environment.

For a list of which parameters you can change, see the section on lists in a LaTeX book. Suggestions:

Leslie Lamport: LaTeX (Figure 5.3 on page 113 in the 1st edition). Gossens, Mittelbach and Samarin: The LaTeX companion (Figure 3.5 on page 62).

## Redefining the font used in figure and table captions.

Often you want figure captions in a different font than the main text (for example slightly smaller, or in italics). Adding e.g. \small in the beginning of each \caption almost works, but there are a few problems. The label (Figure 27:) is not affected by the font changing command. This may be fine in some cases, but will look a bit strange if the font size is changed. If you use a list of figures, the font change command will be included in it, unless the optional argument to \caption is used to make a different (shorter) caption for the list of figures. You may want a way to set the font globally, so it is easy to change (and so you don't forget the font command in figure 27). The solution is adding this to the preamble of your document.

% Different font in captions
\newcommand{\captionfonts}{\small}

\makeatletter  % Allow the use of @ in command names
\long\def\@makecaption#1#2{%
\vskip\abovecaptionskip
\sbox\@tempboxa{{\captionfonts #1: #2}}%
\ifdim \wd\@tempboxa >\hsize
{\captionfonts #1: #2\par}
\else
\hbox to\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}
\makeatother   % Cancel the effect of \makeatletter

Fortunately, you don't have to understand it to use it! Change the first line to choose another font change. NOTE: I cannot get this to work with new-style font commands, so use the old style in the \captionfont definition, i.e. use \em instead of \emph.

## Redefining the label used in captions.

Do you want "Fig. 1" instead of "Figure 1" in all the captions? This is easy, just use

\renewcommand{\figurename}{Fig.}

For tables, redefine \tablename.

## Degree symbol

Create new \grad command like this:

\newcommand{\grad}{\ensuremath{^{\circ}}}

After that, say you want to write 37° C, type 37\grad C.

Edit | Attach | Refresh | Diffs | More | Revision r1.1 - 13 Mar 2006 - 09:24 - MartinBauer

Lehrstuhl für Computer Aided Medical Procedures & Augmented Reality