LaTeX FAQ

Figures

Q How can I adjust the width of a figure width to the column width?
\begin{figure}
    \includegraphics\[width=\linewidth]{filename}
    \caption{}
    \label{}
\end{figure} 
Q How do I make a figure span two columns?
A Use \begin{figure*}_
Q How do I place two figures side by side?
A Make one figure environment containing two minipages, each with its own caption.

Example: Squeak by Example, Environment chapter


Bibtex

Q How do I ensure proper capitalization of proper nouns in bibtex references?
A Enclose the whole word in curly braces: {LaTeX}

NB: Don’t put individual letters in curly braces, as this will make it impossible to search for that word.

Tables

Q How do I make table entries span two or more columns?
A \multicolumn{2}{l}{text}


References

Q How can I make a custom autoref?
A \hyperref[app:mse]{Appendix~\ref{app:mse}}
Q How to change the default autorefs?
 \def\figureautorefname{Figure}%
 \def\tableautorefname{Table}%
 \def\partautorefname{Part}%
 \def\appendixautorefname{Appendix}%
 \def\chapterautorefname{Chapter}%
 \def\sectionautorefname{Section}%
Q How do I turn off the ugly boxes around hyperref links?
A Explicitly set the colors. You can use black too:
\usepackage[pdftex,
	colorlinks=true,
	pdfstartview=FitV,
	linkcolor=black,
	citecolor=black,
	urlcolor=black]{hyperref}
Q How do I fix the error Package hyperref Warning: bookmark level for unknown ... defaults to 0.?
A Remove the \and from author list and use commas instead.


Source Code

Q How can I prepare source code listings?
A \usepackage{listings}

See also http://www.ctan.org/tex-archive/macros/latex/contrib/listings/listings.pdf

\usepackage{listings}
\usepackage{bold-extra}
\lstset{
    language=PASCAL,
    basicstyle=\scriptsize,
    columns= fullflexible
}

\begin{lstlisting}
\end{lstlisting)

For Smalltalk code, use st80.tex. Demo usage: st80demo.tex

Q Verbatim sucks — no commands allowed. What alternatives are there?
A \usepackage{alltt}


Markup

Q How to do bold teletype?
A \usepackage{bold-extra}
Q How do I strikethrough text?
A \usepackage[normalem]{ulem}
\sout{text}.

This package also gives you uline{underlined} and uwave{wavy}. See also the markup macros in scgPaper.tex


Special characters

Q How can I use 8-bit characters directly in my LaTeX document?
A On a mac, usepackage[mac]{inputenc}

NB: This will make your document unusable on other platforms.

Q How do I get guillemets?
A \usepackage[francais,english]{babel}

This makes guillemets accessible as \flqq and \frqq while making the default language English.

Q How do I print a backslash without going into math mode?
A Use \textbackslash
Q How do I encode other special characters?
A Check out the Comprehensive LaTeX Symbol List
Q How do I find the magical incantation for a special character?
A Try Detexify


Spacing

Q How do I control paragraph indentation?
A \setlength{parindent}{0pt}
Q How do I reduce line spacing within lists?
A \setlength{\itemsep}{0pt} within the list

Alternatively, use the paralist package.

Q How can I control double spacing?
A \def\baselinestretch{1.4}

Alternatively:

\usepackage{setspace}
...
\begin{onehalfspace}
...
\end{onehalfspace}

See also: http://en.wikibooks.org/wiki/LaTeX/Formatting#Line_Spacing

Q How do I make sure a block of text is not broken over a page break?
A \usepackage{needspace}
\Needspace{3\baselineskip}


Section heading

Q How do I rename the "References" section?
A \defrefname{Selected publications}


Numbering

Q How do I start numbering an enumeration from a number other than 1?
A \setcounter{enumi}{5} within the list
Q How do I set the page counter?
A \setcounter{page}{1}
Q How do I turn on page numbering for IEEE style?
A \pagestyle{plain}
Q How do I turn on page numbering for ACM SIGPLAN style?
A \documentclass[10pt,preprint]{sigplanconf}
Q How do I turn on page numbering for ACM proceedings style? (acm_proc_article-sp)

\documentclass[preprint]{acm_proc_article-sp} %Remove preprint for camera-ready
\pagenumbering{arabic} % Remove for camera-ready


Special output

Q How do I use LaTeX to generate slides?
A Use http://latex-beamer.sourceforge.net/
Q How do I add a title footnote with LNCS style?
A Use \thanks{}, not \footnote{}
Q How do I generate PDF with quotes that can be copied and pasted into Squeak/Pharo?
A \usepackage{upquote}

This will changes all quotes to be straight.

Q How to install the latest version of PGF/TikZ?
A Make sure that you have the latest TeXLive installation and that all packages are up to date. Locate the URL of the latest PGF build at http://www.texample.net/tikz/builds/. Then execute the following commands in a root shell:
 mkdir /usr/local/texlive/2009/texmf/tex/generic/pgf-2.00-cvs
 cd /usr/local/texlive/2009/texmf/tex/generic/pgf-2.00-cvs
 curl --proxy proxy.unibe.ch:80 $URL -o pgf.zip
 unzip pgf.zip
 rm pgf.zip
 mktexlsr


Last changed by admin on 21 April 2009