LaTeX2e tricks

These tricks work in LaTeX2e documents, very few of them will work in an old-style LaTeX 2.09 document. At sites where LaTeX 2.09 documents are translated by LaTeX2e in compatibility mode (this is the case here at CAMP) some tricks may work, but other people may be unable to use your document if they have an older LaTeX installations. You have been warned!


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:
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:
NOTE: If you use the natbib package, you should use natbibspacing.sty instead, and be sure to load it after natbib:

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:
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:

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:

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.
  1. 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.
  2. 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.
  3. 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

\makeatletter  % Allow the use of @ in command names
  \sbox\@tempboxa{{\captionfonts #1: #2}}%
  \ifdim \wd\@tempboxa >\hsize
    {\captionfonts #1: #2\par}
    \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
\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
For tables, redefine \tablename.

Preventing figures from appearing on a page by themselves.

LaTeX's figure placement algorithm is quite biased in favor of putting figures on a page by themselves, instead of on the top of a page with some text below it. Often, I find the result esthetically unappealing (to be polite). Fortunately, the parameters of the algorithm can be changed. The main problem is that LaTeX per default only allows a part of the top of a text-page (70%) to contain figures, and requires at least 20% of a page to be text when text and figures share a page. These parameters should be set to more reasonable values, for example 85% and 10%.
This helps, but sometimes LaTeX puts a figure on a page by itself, although it would fit perfectly well on the top of a page. This happens when the figure will not fit on the page where it was defined. LaTeX then attempts to put it on a figures-only page before it attempts to put it at the top of the next page. A page may contain figures alone if the figure(s) use at least half the page. To prevent half-empty pages this limit should probably be increased to around 75%.
Be careful not to make \floatpagefraction larger than \topfraction, then you risk to produce a figure that can neither go on the top of a text page, nor on a page by itself. If that happens, the figure and all later figures will be postponed until next time a \clearpage is executed (typically at the end of a chapter or the end of the document). This will also happen if a figure is too large to fit on a page.

Putting the figure and the 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.
      \epsfig{, width=\linewidth}
      \caption{This is the caption.\label{fig:rawss}}
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{, width=\linewidth}}
Or change the [t] optional argument to the minipage environments to [c] or [b]. Experiment!

Including PostScript graphics

Including PostScript graphics can be done in many ways, and there are many pitfalls. The following systematic way usually works, it is based on the \epsfig command, which calls \includegraphics. You may prefer to use \includegraphics directly, or to use the \epsf package, it is a matter of taste.
  1. Include the package: \usepackage{epsfig}
  2. The PostScript picture should contain a well formed bounding box comment indicating where on the paper the figure appears if it is printed, so LaTeX can calculate how to scale and move it to fit where you want it. Many programs produce figures with wrong bounding boxes.
    The bbox command can calculate the bounding box, it works in 95% of the cases. You can also measure it yourself by printing it or using ghostview (preferred). The bounding box command is in the beginning of the file and looks like this:
      %%BoundingBox: 0 10 612 792
    this means that the figure fits inside a rectangle with lower left corner at (0,10) and upper right corner (612,792). The unit is 1/72 inches (.3528 mm) measured from the lower left corner of the paper. Ghostview shows the coordinates of the cursor in the upper left corner, it makes it easy to measure bounding boxes.
    If the bounding box comment is incorrect, fix it or use the bb= argument to \epsfig.
  3. Include the figure where you want it using a command like
      \epsfig{, angle=-90, width=\linewidth}
    this command includes the figure in, rotates it 90 degrees clockwise (good for Xmgr graphs) and scales it to the current line width. LaTeX automatically reserves space for the figure
Useful arguments to \epsfig: The order of arguments is important, the actions are performed in the order specified, so if you scale to a specific width and then rotate, you have in effect scaled to a specific height!

Note when rotating figures: In TeX a box has three dimensions: width, height and depth. Height is how much it goes above the baseline, depth how much it goes below. Epsfig rotates around the lower left corner, so if you rotate by -90 degrees the entire figure ends up below the baseline, i.e. the height is zero but it has a depth. For this reason the height= will not work, but totalheight= does. You may want to use \raisebox to move it above the line.


Discourage hyphenation.

When TeX splits your text into lines it tries to do it the "least ugly" way, by assigning penalties to things that don't look nice (such as words split over two lines). The penalty for splitting a word is rather low, so you may want to increase it when writing texts where split words look bad (in particular posters and viewgraphs). This will produce lines with a little more extra spacing between words, and you should therefore increase TeX's tolerance for such lines. I have found the following values to be useful (put it in the preamble).
You may have to experiment a bit (adjusting \tolerance appears to be most promising). A \hyphenpenalty of 10000 (almost) prevents hyphenation, but produces overlong and/or ugly lines.

Where did I find these tricks?

Most of what this page contains come from one of the following sources. You can look there yourself for solutions to similar problems.
Last modified: 1 September, 1998

Jakob Schiøtz,