Tips: LaTeX

Preamble

Listed on my Latex pages are things that I need to look up nearly every time I use Latex. I first used Latex when I wrote my assignments and dissertation for my MA. I had to look stuff up over and over again, so now that I'm using it again for my PhD, I thought I'd keep a track of things.

I use LaTeX on Windows in the guise of MiKTeX, and use WinEdt as my editor. WinEdt isn't perfect, but it does me.

Use the Latex tips contents to navigate these pages, and see also useful Latex links on this site.

UK List of FAQ

Many people in the UK have questions about LaTeX - a good place to get an answer is the UK List of TeX Frequently Asked Questions on the Web. There's loads of useful stuff here, with questions - and more importantly, answers - about all manner of different LaTeX problems.

"Crazy error: ! Argument of \@sect has an extra }."

If you get this error, it means that you have put what's called a fragile command in a thing called a moving argument. In English, that means you've put a \cite command or a \footnote command or similar in something like a \section heading, like so:

\section{This is a section about \citeasnoun{reference1}}

This will give you the error:

! Argument of \@sect has an extra }.

To fix this, all you have to do is \protect the fragile command as follows:

\section{This is a section about \protect\citeasnoun{reference1}}

See the UK list of LaTeX FAQ for more solutions.

Bibtex: forcing capital letters

To force capital letters in a Bibtex file, put the offending character in curly brackets:

@MASTERSTHESIS{… author = {Old Mc{D}onald}, title = {Having a farm}, type = {M{A} dissertation}, …}

This also works for strings of characters (words, you might call them).

Symbols

There's a really useful document (a PDF) on the Internet, which has the codes for loads and loads of symbols you could ever possibly want to use, and probably more. It comes in A4 and letter size.

Tables: captions and labels

If you have a table and you want a caption and a label, you have to put the label after the caption. No idea why, but it just won't work if you do it the other way round. Also, the caption and label should be outside the tabular block.

Tables: merging columns

To merge columns, use:

column 1 text & \multicolumn{3}{|c|} {multicolumn text - must be in curly brackets} \\ \cline{2-4}

Counters in lists etc.

When using enumerated lists, you can change the value of the counter to something else, for example, if you have a list that's broken up by text, or some such. To do this, use the \addcounter command:

\begin{enumerate} \addtocounter{enumi}{9} \item blah blah \item wibble wibble \end{enumerate}

The style of the counter can be changed as well, for example, to use Roman numerals, Arabic numbers and so on. This can be done in enumerate environments by changing the enumi, enumii etc. counters:

\renewcommand{\labelenumi}{II--\alph{enumi}} \begin{enumerate} \item first item in list \item second item in list \item third item in list \item fourth item in list \end{enumerate}

This will produce a counter II--a, II--b etc.. You may need to remember to put the counter back as it was if this is only a temporary change.

\renewcommand{\labelenumi}{\arabic{enumi}}

The same effect can be achieved in the list environment without changing the built-in counters by setting up a new counter as follows:

\newcounter{newC}
\begin{list}{II--\alph{newC}} {\usecounter{newC}} \item first item in list \item second item in list \item third item in list \item fourth item in list \end{list}

Note the curly brackets around the \usecounter command. Settings such as margin width for indentation purposes may be set inside the curly brackets following the \usecounter command. Also note that references to labelled items will not work as expected here. I'll get round to typing this up one day, maybe!

See also Help on LaTeX Counters for more information.

Strikeout and other line effects

For strikethrough/strikeout and other line effects: use the ulem package. This package changes text marked to be emphasised by underlining rather than by italicising text. This will affect things like bibliographies, where book titles, for example, that are normally italicised are underlined instead. I find this undesirable, but the author's thought of that already: it's possible to switch between default behaviour and non-default behaviour.

In the preamble:

\usepackage[normalem]{ulem}

This will tell LaTeX that you want default behaviour as a rule.

In the main text:

When you want special underlining/strikeout text, add the following switches:

\ULforem % Switches on underlining/strikeout for \em text text \sout{text} text \normalem % Switches off underlining/strikeout for \em

Remember to switch the behaviour off again!

Possible options are:

\uline{text}
singly underlined text
\uuline{text}
doubly underlined text
\uwave{text}
wavily underlined text
\sout{text}
strikeout text
\xout{text}
text overlaid with strokes (forward slashes)

It is possible to view the contents of ulem.sty. There is also some documentation about ulem.sty.

Indices and glossaries

You can get LaTeX to do indices and glossaries for you. There are similar commands for each, which are outlined here.

Accented characters in a tabbing environment

Problem: accented letters don't display properly within the tabbing environment in LaTeX, even if you put curly brackets around them.

Solution: use the Tabbing (with a capital T) environment instead. This requires a couple of alterations to the symbols used in the ordinary tabbing environment:

  • Instead of using \=, use \TAB=.
  • Instead of using \>, use \TAB>.

You should be able to get accented characters as per normal, either with curly brackets (\'{e}) or without (\'e).

You'll need to use the Tabbing.sty package to use the Tabbing environment.

Blank lines

A double back-slash (\\) is used to create a new line. It can also be used to create the appearance of a blank line - extra whitespace - between one line and the next by using the optional arguments (\\[*][extra-space]). The extra-space argument specifies how much whitespace should be left between this line and the next, and be positive or negative (or zero, of course). If the \\* version is used, LaTeX will not start a new page after the blank line.

text text text\\[10pt] A new page can follow this line.
blah blah blah

text text text\\*[10pt] The next line must be on the same page as this line.
blah blah blah