Tim Evans LaTeX Tips Page

Tim Evans Computing Tips Home Page | Tim Evans Informal Home Page | Tim Evans Imperial College page

LaTeX

Google "Useful LaTeX Guides" to find some of the many guides. I like "The Not So Short Introduction to LATEX2" by Oetiker Partl, Hyna and Schlegl (v.4.24 is dated Feb 2008). There is a also a good looking Wikibook on LaTeX. Another good place looks like the LaTeX Community web site. Some of these tips came from Andy Roberts LaTeX typesetting tutorial.

For a suggestion on how to install LaTeX under Windows see my page on Windows.

Simple Tips

Page Size and Orientation

Some of these tips came from Andy Roberts LaTeX typesetting tutorial.

The default page size leaves too much white paper for my taste. One way is alter this is to use \usepackage[a4paper]{geometry}. This package has many other options including a0paper, a1paper, ..., a6paper, b0paper, b1paper, ..., b6paper, letterpaper, legalpaper, executivepaper. For more control you can use

\usepackage[top=length, bottom=length, left=length,right=length]{geometry}

You can also combine these with orientation commands \usepackage[a4paper,landscape]{geometry}. For instance I have tried the following:-
% See geometry.pdf to learn the layout options. There are lots.
\usepackage[a4paper,top=2cm,bottom=2cm,left=2cm,right=2cm,marginparwidth=1cm]{geometry}

I use more explicit commands for drafts to minimise waste which should be OK for both Letter and A4 paper:-

\typeout{--- Increasing width and height of text }
% A4 paper is 29.5cm high and 21cm wide.
% Letter paper is 28cm by 21.5cm
\setlength{\textwidth}{15.92cm} % OK for both Letter and A4
\setlength{\oddsidemargin}{0cm}  %margins = 1inch +
                                 %top/odd/even-sidemargin
\setlength{\evensidemargin}{0cm} %  ditto
\setlength{\topmargin}{-1.0cm}      %  ditto
\setlength{\headheight}{18pt} \setlength{\headsep}{6pt}
\setlength{\topskip}{0pt}  %see pp155 also about baselineskip
\setlength{\textheight}{25.0cm} % 25cm for A4, 23cm for Letter or DJ
\setlength{\footskip}{0.7cm}

Including Graphics

Use google to find useful guides such as "Using imported Graphics in LATEX and pdfLATEX" by Keith Reckdahl (v.3.0.1 is dated January 12, 2006).

You need to put a

\usepackage{graphicx}
command near the top of the LaTeX file, just after the documentclass command. Only use postscript figures in general if you want postscript output from dvips. pdflatex and other pdf compilers can cope with PDF, PNG, JPEG and GIF images. Alternatively, my current approach is to produce both an eps and a pdf figure at the same time, differing only in the file extension. These are both rescalable if the figure was produced ina vector format. I often produce a bitmap image (jpg, bmp etc) at the same time as it is useful for Powerpoint, web sites etc. Then if you then use the file name without the extension in the includegraphics command, LaTeX will select the correct version (eps or pdf) by default and both pdfLaTeX and other types of LaTeX will run from the same tex file.

When including the graphics file, scaling as needed is easily added as the following examples show:

  \includegraphics{myfig}
  \includegraphics[width=60mm]{myfig}
  \includegraphics[width=0.25\textwidth]{myfig}
  \includegraphics[height=60mm]{myfig}
  \includegraphics[height=80mm,width=60mm]{myfig}
  \includegraphics[scale=0.75]{myfig}
  \includegraphics[angle=45,width=52mm]{myfig}
You need the file myfig.eps to be present in the same directory as the LaTeX file if straight LaTeX is used, otherwise you will need a myfig.pdf to be present. Unix style directory names may be part of file names too.

A trick to avoid typing the same directory in the filenames all the time is to place all files in a subdirectory of the main LaTeX file but to tell LaTeX where this using

\graphicspath{{./Figures/}}
Note the forward slashes for a Windows machine. This means it will look for ./Figures/myfig.pdf etc.

Note that I have had problems with bounding boxes. That is pdf or eps figures can sometimes be treated as having a very large size (e.g. whole page). For instance PDF export from draw in Libreoffice fails to put a bounding box in the file. For eps files, the GsView viewer will allow you to add a bounding box so you can do this by hand. For pdf solutions include using briss (java, all platforms) or pdfcrop or pdfcropper (Windows). I tried using ImageMagik (

convert file.eps file.pdf
) but it worked via a bitmap conversion.

To put the caption beside a figure try the following:

\begin{figure}
  \begin{center}
    \begin{minipage}[b]{0.58\linewidth}
      \raisebox{-0.5cm}{\includegraphics[width=6cm]{myfig}}
    \end{minipage}\hfill
    \begin{minipage}[b]{0.38\linewidth}
      \caption{Caption here and label too.\label{figurelabel}}
    \end{minipage}
  \end{center}
\end{figure}
The positioning still can go funny. The optional argument to the minipage environments can be changed to [c] or [t] or use a \raisebox command to raise the figure (as shown here) or the caption as needed.

Subfigures can be included using

\usepackage{subfigure}
.

Placing Figures and Tables (floats)

The problem is that LaTeX will not put too many floats (figures, tables, etc.) on one page and it will always put them in the output in the order it encounters them. So it can have a large number of figures to output but it is still only putting one or two on each page and they are placed a long way from the relevant text. Andrew Young wrote some useful hints on LaTeX floats and this is a summary of options:-

Andrew Young suggests the standard values set in class files such as article are too restrictive and suggests the following redefinitions

    % Alter some LaTeX defaults for better treatment of figures:
    % By Andrew Young, see http://mintaka.sdsu.edu/GF/bibliog/latex/floats.html
    % See p.105 of "TeX Unbound" for suggested values.
    % See pp. 199-200 of Lamport's "LaTeX" book for details.
    %   General parameters, for ALL pages:
    \renewcommand{\topfraction}{0.9}	% max fraction of floats at top
    \renewcommand{\bottomfraction}{0.8}	% max fraction of floats at bottom
    %   Parameters for TEXT pages (not float pages):
    \setcounter{topnumber}{2}
    \setcounter{bottomnumber}{2}
    \setcounter{totalnumber}{4}     % 2 may work better
    \setcounter{dbltopnumber}{2}    % for 2-column pages
    \renewcommand{\dbltopfraction}{0.9}	% fit big float above 2-col. text
    \renewcommand{\textfraction}{0.07}	% allow minimal text w. figs
    %   Parameters for FLOAT pages (not text pages):
    \renewcommand{\floatpagefraction}{0.7}	% require fuller float pages
   % N.B.: floatpagefraction MUST be less than topfraction !!
    \renewcommand{\dblfloatpagefraction}{0.7}	% require fuller float pages
   % remember to use [htp] or [htpb] for placement

Note that putting an exclamation mark in the placement argument makes LaTeX ignore all constraints except for \topfraction, \bottomfraction, and those with floatpage in their names. Also note the order placement options are given to LaTeX is irrelevant, it does not express a preferred position but just possible positions.

Wrapping text around figures

This comes from WikiBook on LaTeX. I have used the wrapfig package successfully. To do this pace the \usepackage{wrapfig} in the preamble and then in the main text try something as simple as
\begin{wrapfigure}{r}{0.3\textwidth}
  \begin{center}
    \scalebox{0.3}{\includegraphics{fig0sfnetworkpicture.eps}}
  \end{center}
\end{wrapfigure}

Beamer and Presentations

Unless you really have a lot of equations I suggest that LaTeX and Beamer is not ideal. I spend a lot of time making small adjustments to code, then rerunning it to see what it looks like. It takes a lot longer than the WYSIWYG approach of Powerpoint or equivalent. Adding annotation to figures is also a pain unless you have a good vector graphics editing package with pdf output (so a copy of Adobe is needed). However here are some of the tips I have found useful. Graphics are the big problem. Beamer seems to work best for me with pdf LaTeX. Producing dvi and then converting to postscript gave me lots of ps errors when trying the dvi viewer. For this reason I have to produce my figures in anything but eps format. I tend to produce pdf format for vector graphics, and then the native format for bitmap as pdflatex deals with those too. I produce sketches and diagrams in LibreOffice draw. The big problem is that the pdf figures come our on a full page of A4. The trick is to select the part required, export selecting both the eps format and ticking the selection box, then finally I convert the eps format to pdf using
ps2pdfr -dEPSCrop graphic.eps graphic.pdf
Some of the basic options of Beamer. I use one of the first two for a large lecture theatre. The first gives you presentation mode with several slides
\documentclass[bigger]{beamer}
\documentclass[bigger,handout]{beamer}
\documentclass[smaller]{beamer}
\documentclass[11pt]{beamer} % Default
\documentclass[12pt]{beamer} % Bigger option produces this Makes all fonts a little bigger, which makes the text more readable.
\documentclass[14pt]{beamer} % Makes all fonts somewhat bigger. Requires extsize to be installed but worked without intervention on my system
For partial revealing and to deal with handouts you need the commands
    \uncover<3->{This makes LaTeX treat the space as occupied even though the content is only seen on slides 3 or later}
    \only<2>{This will only place the content on slide 2 so spacing on other slides will not be effected by this}
    \only<2| handout:1>{In presentation mode content appears on slide 2, but if creating handouts this will place the content on handout page 1}
    \only<2| handout:0>{In presentation mode content appears on slide 2, but if creating handouts this will not place this content on any handout page}

BibTeX

To work with a bibtex file try something like
\bibliographystyle{elsart-num}
\bibliography{/DATA/JabRef/TSEjabrefdatabase}
I like JabRef which is open source, java based so multi-platform and can import most of the bibliography formats produced from journals and other web sites. N.B. I use
[auth1_1][auth1_2][auth1_3][auth1_4][auth1_5][auth1_6][auth1_7][auth1_8][auth1_9][shortyear]
as the bibtex key generator default pattern (under preferences). The drawback is that I do not find any of the BibTeX styles very nice. Currently I like the elsart-num.bst from the publishers Elsevier or the but it looks like a chore to design your own and someone must have one I like. Even the journal's own styles do not seem to produce the correct output. There is a standard document showing many standard styles entitled "BibTeX Style Examples"e; and a database of styles. My solution is to paste the .bbl file produced by BibTeX to replace the BibTeX bibliography commands above. The .bbl file is a normal LaTeX bibliography. I do this when the article is nearly finished. One problem with BibTex and JabRef is that it is a very loose standard, importing BibTeX from another source can produce strange results. One nice trick is to use Bib2x converter. Convert to BibTeX and it seems to tidy up the mess so that most other things can then read the file. In general look at BibTeX.org for more information. I use files stored in different places on different computers. To solve this you can use code such as this
\IfFileExists{dagshared.bib}{\bibliography{dagshared.bib}}{}
\IfFileExists{/Users/myname/gDrive/PAPERS/JabRef/TSEjabrefdatabase.bib}{\bibliography{/Users/myname/gDrive/PAPERS/JabRef/TSEjabrefdatabase}}{}
\IfFileExists{/Users/myothername/gDrive/PAPERS/JabRef/TSEjabrefdatabase.bib}{\bibliography{/Users/myothername/gDrive/PAPERS/JabRef/TSEjabrefdatabase}}{}

Author-Year Citation style

This is the style often used in social sciences and humanities. The key is the natbib package. It does not work with every other package, sometimes reading in last helps so try removing packages or searching the web if you have problems.
\documentclass[a4paper,12pt]{article}

% This does the business
\usepackage{natbib}

% Note that there are extra cite commands
% Mostly you use \citep or \citet
% The \cite command functions as follows:
%   \citet{key} ==>>                Jones et al. (1990)
%   \citet*{key} ==>>               Jones, Baker, and Smith (1990)
%   \citep{key} ==>>                (Jones et al., 1990)
%   \citep*{key} ==>>               (Jones, Baker, and Smith, 1990)
%   \citep[chap. 2]{key} ==>>       (Jones et al., 1990, chap. 2)
%   \citep[e.g.][]{key} ==>>        (e.g. Jones et al., 1990)
%   \citep[e.g.][p. 32]{key} ==>>   (e.g. Jones et al., 1990, p. 32)
%   \citeauthor{key} ==>>           Jones et al.
%   \citeauthor*{key} ==>>          Jones, Baker, and Smith
%   \citeyear{key} ==>>             1990

\begin{document}
Data is never perfect. However, when it is good, as is often the case in the physical sciences, there are various programmes for tackling data deficiency \citep[e.g.\  ][]{KO01,BKS14}.

This is where modelling can add to the debate. How to make the best use of our ignorance is an old problem and we shall not attempt to document its history much beyond the observation that economists, who popularised the approach in the 20th century, refer to it \citep[see][chapter 4]{K21} as Laplace's `Principle of Indifference',  although Laplace himself termed it the `Principle of Insufficient Reason' \citep{L25}.

% *****************************************************************
%
% BIBLIOGRAPHY
%
% **************************************************************
% Uses BibTeX
%

\bibliographystyle{unsrtnat} for natbib
%\bibliographystyle{unsrt} use for non-natbib

% Tell it where the bibliography file is, this is for the file eaaglasgow.bib in the same directory as the tex file.
\bibliography{eaaglasgow}
%\IfFileExists{/Users/TEvan_000/OneDrive/PAPERS/JabRef/TSEjabrefdatabase.bib}{\bibliography{/Users/TEvan_000/OneDrive/PAPERS/JabRef/TSEjabrefdatabase}}{}

\end{document}

Saving Space

These tips came from LaTeX Tips n Tricks for Conference Papers

\usepackage{times} will use Times font instead of the default, saving significant space.

\usepackage[small,compact]{titlesec} will modify section titles and the spacing above/below them, resulting in significant space-savings.

\usepackage[small,it]{caption}

\def\Section {\S} allows you to replace the rather long "Section 5" by §5 when you use \Section 5.

The itemize environment can be replaced by:
\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{\squishlisttwo}{
   \begin{list}{$\bullet$}
    { \setlength{\itemsep}{0pt}    \setlength{\parsep}{0pt}
      \setlength{\topsep}{0pt}     \setlength{\partopsep}{0pt}
      \setlength{\leftmargin}{2em} \setlength{\labelwidth}{1.5em}
      \setlength{\labelsep}{0.5em} } }

\newcommand{\squishend}{
    \end{list}  }
Example usage:
\squishlist    %% \begin{itemize}
\item First item
\item Second item
\squishend     %% \end{itemize}

Bibliography can be shrunk as follows:
{\scriptsize
 \bibliographystyle{abbrv}
 \bibliography{references}
}
Replace \scriptsize by \footnotesize or \small depending upon your comfort-level of font-shrinkage.

The standard \maketitle consumes significant space. Many conferences do not dictate a style-file for initial submission. Thus you could create your own compact title! What follows below is for \twocolumn articles (see also below):
 \documentclass[twocolumn]{article}

 %% The usual stuff that sits
 %% between \documentclass and \begin{document}

 \begin{document}

 \twocolumn[%
 \centerline{\Large \bf A Randomized ID Selection Algorithm
 for Peer-to-Peer Networks}           %% Paper title

 \medskip

 \centerline{\bf Gurmeet Singh Manku} %% Author name(s)
 \bigskip
 ]

 %% The rest of the paper (with no maketitle)

 \end{document}
Notes: \twocolumn is a TeX command. There is no \maketitle.

The affiliation and email of authors can be moved down to footnotes by using \thanks:
\author{Gurmeet Singh Manku\thanks{Computer Science Department,
Stanford University. EMail: manku@cs.stanford.edu}}

The bibliography file has the extension .bst. Several bibliography styles print full names of authors. It is possible to modify the .bst file so that only the initials appear. Look for a line that looks like FUNCTION {format.names}. Within that function, use the following:
{ s nameptr "{f{ }~}{v~}{ll}{,  jj}" format.name$ 't :=
Explanation: the .bst file format uses post-fix notation. The crucial piece is the string following the variable-name nameptr -- this string specifies the format. Leave everything else untouched. With some more "hacking", it is possible to get rid of months and to shrink pages to simply p. Check out BibTeX site for further info.

\usepackage{mathtime} is supposed to handle math with Times font better.

URLs require the ~ symbol, which can be created simply with $\sim$. This is not a real ~ but looks much better (since it is bigger).

Bibliography: Don't forget to use curly-braces in paper-titles when they are necessary! Without the braces in title = " Foo-bar for {TCP/UDP} bar-foo", the citation will be printed as "Foo-bar for tcp/udp bar-foo" (note the small-case for "TCP/IP"). Surround all acronyms and proper nouns with curly-braces and capitalise any letters you wish to retain as such.

Two Columns

These tips came from Andy Roberts LaTeX typesetting tutorial.

Use the twocolumn option in article as \documentclass[twocolumn]{article}. It defines a multicols environment so when you want two columns use

\begin{multicols}{2}
  blah blah blah
\end{multicols}
You can mix and match number of columns. If you want vertical rules change this default setting of \columnseprule from 0 (no rules) to say \setlength{\columnseprule}{1pt}. Space between columns is altered using \setlength{\columnsep}{20pt} (default 10pt). Note graphics are not fully catered for, use \begin{figure*}

Posters

For a good poster class try baposter.

RevTeX

The A brief and concise description of RevTeX 4 package looks like a useful source. Some useful options for RevTeX are found by googling revtex options or try these in various combinations
\documentclass[preprint,pre]{revtex4}
\documentclass[showpacs,onecolumn,amsmath,amssymb]{revtex4}
\documentclass[preprint,nofootinbib,amsmath,amssymb]{revtex4}
\documentclass[twocolumn,nofootinbib,amsmath,amssymb,preprintnumbers]{revtex4}