Latex tips and tricks

Latex is a document preparation system. It is an amazing tool to edit texts, create presentations and much more allowing the author to concentrate on the contents, rather than on the formatting of a document. It works great out of the box, but sometimes it can lead to some headaches. To minimize these occurrences and to have a readily accessible list of howto, I am listing here some of the tips and tricks I've adopted to solve my problems. These solutions come from various sources freely available on the net or from manuals. For a (non exhaustive) list of sources, please check the links at the end of this page.

Tips and tricks for text editing

How to trim a figure

Add the following line in the preamble:

\usepackage{graphicx}

Then you can trim your figure as follows:

\begin{figure}[htbp]

\includegraphics[trim = left bottom right top, cliop]{file}

\end{figure}

How to make a list with "i." symbols

Add the following line in the preamble:

\usepackage{paralist}

Then you can write your list as follows:

\begin{compactenum}[i.] %%sets the symbol to be used in the list.

\item{first item;}

\item{second item.}

\end{compactenum}

How to make section numbering independent from chapter numbering

Add the following line in the preamble:

\def\thesection{\arabic{section}}

Eliminating the dots from the Table Of Contents

Add the following lines in the preamble:

\makeatletter

\renewcommand{\@dotsep}{500}

\makeatother

Removing the horizontal line before the footnotes

Add the following lines in the preamble:

\renewcommand{\footnoterule}{%

\kern -3pt

\hrule width \textwidth height 0pt

\kern 3pt

}

How to use PSTricks with PDFLatex

Add the following line in the preamble:

\usepackage{pst-all}

To generate the pdf file follow these steps:

1. move to the directory with yourdocument.tex;

2. latex yourdocument.tex;

3. dvips -Ppdf -G0 yourdocument.dvi;

4. ps2pdf yourdocument.ps

If you have also a bibtex file then run:

5. bibtex yourbibfile.bib

6. repeat steps 2 to 4.

How to change the font size of the bibliography

If you use the NATBIB package, add the following line in the preamble:

\def\bibfont{\footnotesize} %%attributes the footnotesize to the bibliography font.

If you use the BIBLATEX package, add the following line in the preamble:

\renewcommand*{\bibfont}{\footnotesize} %%attributes the footnotesize to the bibliography font.

How to place 2 figures side by side

Add the following line in the preamble:

\usepackage{subcaption}

\begin{figure}[h]%
\begin{subfigure}[h]{0.4\textwidth}    
\includegraphics[width=\textwidth]{<the name of the first file>}    
\caption{<The caption of the first figure>}
\end{subfigure}
\quad                         %%includes a vertical space between the two figures.
\begin{subfigure}[h]{0.4\textwidth}   
\includegraphics[width=\textwidth]{<the name of the second file>}    
\caption{<The caption of the second figure>}
\end{subfigure}%
\caption{<The caption of the overall figure>}
\end{figure}

How to create a new command with optional arguments

Add the following lines in the preamble:

\newcommand{\nameofthecommand}% %%\newcommand{} allows to declare a new command. In braces put the name of the new command.

[3] % %%in the first square brackets declare the number of arguments to pass to the new command.

[i] % %%in the second square brackets eventually declare any default value for the first argument.

{\ensuremath{% %%in this case the command produces a mathematical symbol. The command \ensuremath{} takes care of the braces.

\Gamma^{#1#2}_{#3}} % %%finally, define the function the new command should perform.

}

Tips and tricks for Beamer presentations

How to include a logo

Add the following line in the preamble:

\logo{\includegraphics[width=0.20\textwidth]{<your picture>}}

How to set a picture for the background

Add the following line in the preamble:

\usebackgroundtemplate{\includegraphics[width=\paperwidth]{<your picture>}}

To set the picture for the background of a single slide:

Put the \usebackgroundtemplate{} command within a group including the frame environment:

{ \usebackgroundtemplate{\includegraphics[width=\paperwidth]{./gph/guess}} \begin{frame} put some content here \end{frame} }

How to add page numbers in each slide

Add the following line in the preamble:

\setbeamertemplate{footline}[frame number]

How to add a text line at the bottom of each slide

Add the following line in the preamble:

\setbeamertemplate{footline}[text line]{Add your text here!}

How to personalize the contents of the footline

Add the following lines in the preamble:

\newcommand{\Ffootline}{% %%defines a new command called \Ffootline

\insertshortauthor %%puts the abbreviated form of the author's name in the left corner

\hfill

\insertshortinstitute %%puts the abbreviated form of the author's institution in the middle

\hfill

\insertframenumber/\inserttotalframenumber} %%includes the current slide number over the total slide number in the right corner

Finally, we inform latex to include the newly created command in the footline:

\setbeamertemplate{footline}{% %%sets the options for the footline

\usebeamerfont{structure} %%uses the same fonts adopted for the structure of the presentation

\Tiny\hspace*{4mm} \Ffootline \hspace{4mm} %%sets the size of the font to Tiny and includes the content of the \Ffootline

} %%command leaving a margin of 4mm to the right and left of the content.

How to split the frame into columns

Add the following lines in the frame:

\begin{columns} %%starts the column environment

\column{0.50\textwidth} %%sets the first column to 50% of the width of the text

content of the first column %%include text, images or charts here

\column{0.50\textwidth} %%sets the second column to 50% of the width of the text

content of the second column %%include text, images or charts here

\end{columns} %%closes the column environment

Note: you can include more than two columns in the same frame. Just make sure the width of columns

adds up to 100.

How to change fonts

Add the following lines in the preamble: \usepackage[T1]{fontenc}

\usepackage{fontstyle} %%where fontstyle can be one of the following freely

%%available fonts:

lmodern %%Latin Modernmathptmx %%Times with Math style

mathpazo %%Palantino

charter %%Charterbookman %%Bookmannewcent %%New Century Schoolbook helvet %%Helvetica (Arial)cmbright %%CM-Brightavant %%Avantgardcourier %%Courierluximono %%Luxi Mono


List of useful web resources for Latex

http://tex.stackexchange.com

http://en.wikibooks.org/wiki/Latex

http://latex-community.org/forum/

http://www.personal.ceu.hu/tex/cookbook.html

http://www.guitex.org/home/it/tex-gallery