Handy LaTeX syntax I Googled over the years

In an attempt to ease the transition from Word to LaTeX for some of my colleagues (*cough* Alex *cough*) this blog post covers some LaTeX tricks I use most frequently when preparing manuscripts. It’s pitched at someone who is already familiar with the basic syntax of paragraphs, figures and tables.

[If you’re not already doing so, you can ease your job by using Overleaf and starting from one of the many fantastic LaTeX templates available there: https://www.overleaf.com/latex/templates]

1. Changing the text format is particularly useful when making notes to self about parts of your manuscript that still need to be modified or for highlighting textual changes to reviewers.

First, ensure the ‘xcolor’ package is imported:

\usepackage{xcolor}

Then to colour a chunk of text in red:

{\color{red}{text to be coloured}}

To yellow-highlight a chunk of text:

{\colorbox{yellow}{text to be highlighted}}

Use an “!” to tune the intensity of the color:

{\colorbox{yellow!10}{highlights in pale yellow}}
{\colorbox{yellow!50}{highlights in strong yellow}}

Bold text:

\textbf{text to be emboldened}

Italic text:

\textit{text to be italicised}

Underline text:

\underline{text to be underlined}

Strikeout text:

\usepackage{soul}
\st{text to be struck out}

2. Got a large landscape figure/table that needs rotating so that it fits on the page? Use the rotating package.

For elements rotated 90 degrees anti-clockwise:

\usepackage[figuresright]{rotating}

For elements rotated 90 degrees clockwise:

\usepackage[figuresleft]{rotating}

and either:

\begin{sidewaysfigure}
...
\end{sidewaysfigure}

or:

\begin{sidewaystable}
...
\end{sidewaystable}

3. Figure syntax also helps to guide figures to display the way you want them.

\begin{figure}[ht]

>The letters in the square brackets tell latex where you want the figure. h = here, t = top of page, b = bottom of page. You can supply an exclamation mark to get Latex to ignore some placement restrictions and make the figure more likely to appear where you want it, e.g. \begin{figure}[ht!]

\includegraphics[width=0.9
\textwidth]{my_figure.png}

>If you find your figure isn’t appearing where you want it to be, it’s probably violating some margin restriction may need to be shrunk in size to fit. Adding the width tag allows you to adjust the size of the figure relative to the pagewidth and overcome the restriction.

\begin{figure}

vs

\begin{figure*}

>In most two-column latex templates one will render the figure within a single column and the other as a full-page figure that spans both columns.

\begin{table}
\begin{tabular}[|l|l|l|]
\end{tabular}
\end{table}

> l = left aligned; | = where the column rules will be. So this is a three-column table where there is a vertical line on the left, right, and dividing each column. \begin{tabular}[lll] would have three left-aligned columns but no vertical lines.
alternative letters: c = centre, r = right-aligned

\begin{tabular}[|l|l|l|l|]
\multicolumn{2}{c}{My text centralised spanning the first two columns} & \multicolumn{2}{c}{My other text centralised spanning the last two columns}\\
...
\end{tabular}
\end{table}

>The multicolumn command provides an easy way to format column headings that span multiple columns. The “c” letter overrides the “l” alignment in the square brackets for these cells only.

\vspace{2cm}
\vspace{-0.5cm}

>Helps space out or compress components of a figure/table if the spacing is a bit too tight or too generous. Often handy for captions, but also useful outside of the context of figures/tables.

4. Accented characters are called by writing a backslash, followed by the key that represents the accent type [not always obvious], followed by the letter in curly brackets.
e.g.
soirée is written soir\’{e}e
château is written ch\^{a}teau
mañana is written man\~{n}ana
Å is written \r{A}

More examples here: https://en.wikibooks.org/wiki/LaTeX/Special_Characters

5. “Math mode” (enclosed with $ tags) can not only useful for writing mathematical equations, but can also provide access to common special characters:
e.g.
~ (a mid-height tilde) is achieved using $\sim$ rather than \textasciitilde, which typically sets it as ˜.
αβTCRs is written as $\alpha\beta$TCRs
≥ is written as $\geq$

More examples here: https://www.cmor-faculty.rice.edu/~heinken/latex/symbols.pdf

Author