Hippocamplus My Second Memory


A lot of good information in the LaTeX Wikibook.

Standard packages

This is my default (more or less) :

\usepackage{amsmath, amssymb, amsthm}


TinyTeX is a lightweight LaTeX distribution where we download only what we need. It’s a R package. Once installed, run install_tinytex() to install a first version of TinyTeX. Then install additional packages with tlmgr_install("pkg"). To find which package provides a particular xxx.sty run tlmgr_search("/xxx.sty").


  • Use ~ to make sure words are not split by line wrapping, e.g. a good habit: Fig~\ref{..}.

Document class

\documentclass[12pt, a4paper]{article}
  • Classic classes: article, report, book.
  • Default font size is 10pt.
  • Other cool options: twocolumn, landscape.

Page size

Page types in \documentclass[letterpaper]{article} include letterpaper, a4paper (and more).

Custom page/margins:

\usepackage[paperwidth=8.5in, paperheight=11in, top=0.5in, bottom=0.5in, left=1in, right=0.5in]{geometry}

Or margin= to apply the same margin on each side.

Font sizes

\tiny, \scriptsize, \footnotesize, \small, \normalsize, \large, \Large, \LARGE, \huge, \Huge.

Change the symbol in lists


Here are some appropriate symbols: \ast, \star, \diamond, \blacktriangleleft, \blacktriangleright, \rightarrow, \Rightarrow.

Math calligraphy

The two most popular math calligraphy are used with :

  • $\mathcal{A}$ for calligraphy.
  • $\mathbb{A}$ for blackboard (e.g. sets).
  • $\mathbf{A}$ for bold.

Languages and encoding

At some time when writing in French or Spannish I used:




An accent was specified as \'i.

Table of contents

Changing the title of the section created by \tableofcontents:

\renewcommand{\contentsname}{Table of Contents}

To manually add an un-numbered section to the TOC (here at the chapter level):


To set the depth of the TOC:


To set the space between the number and the title in list of figures/tables (e.g. if custom long numbers):



To specify the PDF’s metadata (title, author, etc):




  • [h] means here.
  • [t] means at the top of the page.
  • [p] means on its own page.

I usually use [ht] for small/medium figures, and [htp] for large ones.


After adding \usepackage{subcaption}, use like this:


For more custom organization of the sub-figures, feel free to use minipage environment. To force a caption number/letter, use \addtocounter{subfigure}{XX}. For example, to have the second subfigure as a long vertical panel on the right and figure {} and {}, smaller on the left:

    \caption{Whole figure caption}

Supplementary figures

The counter and style for supplementary figures (and tables) can be changed. I place this block at the beginning of the supplementary figure section:


Moreover, some journals require the supplementary figures to be named Supplementary Fig. 1. As it is, with the configuration above, it would look like Fig. S1 when using Fig. \ref{fig:toto}. The only solution I can think of is to manually write or not the Supplementary and remove the S in the number. But it’s painful. Eventually I could write a small script that does this automatically.

Side-note: I don’t like this style. Ok it looks a bit more fancy but using S12 is shorter and clearer, and avoids any confusion even when citing multiple figures.

To list tables: \listoffigures


Control tabular width


Add vertical padding


Supplementary tables

Similar to figures I use:


To list tables: \listoftables

Spanning columns/rows

  • \multicolumn{2}{c|}{Multi-column} for a column spanning 2 columns.
  • \multirow{2}{*}{Multi-row} for a row spanning 2 rows.
  • \cline{2-10} to avoid \hline crossing a multi-row cell (one the first column).

Align columns

In Emacs, place the cursor within the tabular and press M-x align-current.

Rectangular selection/cut/paste

In Emacs, the columns can be “easily” rearranged using rectangular selection. Depending on Emacs’ version it could be:

  • C-x space starts the selection.
  • C-x r k cut the selection.
  • C-x r y paste the selection, considering the cursor in the top-left corner of the desired location.

Tables from R

Package knitr has a function kable to easily format a data.frame in LaTeX format.

Code blocks

The easiest is to use Listings environment.

In Emacs to avoid misinterpreting special character (e.g. $ or _) I added to .emacs :

(setq LaTeX-verbatim-environments-local '("lstlisting"))

Then in the LaTeX document I setup the lstlisting environment with something like:

  basicstyle=\scriptsize\ttfamily, % the size of the fonts that are used for the code
  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
  breaklines=true,                 % sets automatic line breaking
  frame=single,                    % adds a frame around the code
  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code
  language=sh,                     % the language of the code

For manuscripts


An abstract environment exists:

Genetics has been shown to be important...

Author affiliation

Using \usepackage{authblk}, the authors’ affiliations can be defined like this:

\author[1,2]{Jean Monlong}
\affil[1]{Department of Human Genetics, McGill University, Montréal, H3A 1B1, Canada}
\affil[2]{McGill University and Génome Québec Innovation Center, Montréal, H3A 1A4, Canada}

Text formatting

  • \linespread{1.6} for double-spacing.
  • To add line numbers, lineno package:

Notes/comments using the todo package

To set the font size or width for all notes:

%% avoid the todo notes going out of the margin

An example of inline note specifying an author: \todo[inline,author=NAME]{The note's content}

Slightly nicer custom comment commands, bolding the author and adding a comment number:

    %\setstretch{0.7}% spacing
    %\setstretch{0.7}% spacing

Then, add a note with \comment[NAME]{This is a comment} or \commentil[NAME]{This is an inline comment}.

Main text and supplements in two documents

It’s easier to have the two documents separated with their own bibliography. Then no need to manually split the pdf (and likely lose links).

Using the xr package, we can specify other documents where to find references (figures, tables, sections).

In the main.tex document:


And in the suppmat.tex document:


On Overleaf, they use a variant where the suppmat.tex is not compiled but its references can still be used in the main.tex using:

\newcommand*{\addFileDependency}[1]{% argument=file name and extension
  \IfFileExists{#1}{}{\typeout{No file #1.}}


and a latermkrc file with:

add_cus_dep( 'tex', 'aux', 0, 'makeexternaldocument' );

sub makeexternaldocument {
    if (!($root_filename eq $_[0]))
        system( "latexmk -cd -pdf \"$_[0]\"" );

Compare versions and highlight revisions

The latediff Perl script works well. For example to compare two versions I use:

git show COMMIT:main.tex > main-old.tex
git show COMMIT:suppmat.tex > suppmat-old.tex

latexdiff main-old.tex main.tex > main-diff.tex
latexdiff suppmat-old.tex suppmat.tex > suppmat-diff.tex

Then compile main-diff.tex and suppmat-diff.tex normally.

One figure = one file

I’d like to do some observational humor for you now, I hope you can identify with it: hey ! Don’t you hate… when you have finished preparing a submission and you realize you have to save every supplementary figure in its own file ?

Joke/frustration aside, a quick way to do that keeping the sub-figures organization together and the PDF format, is to reformat the latex file to remove the figures’ \caption and the page numbers (\pagestyle{empty}) and run something like:

for ii in `seq 1 20`
    pdfjam SuppFigs.pdf $ii -o temp.pdf
    pdfcrop --margins 10 temp.pdf FigureS$ii.pdf


I use \usepackage[comma,super]{natbib} and the commands:


Reduce long list of authors

To change a long list of authors into “First Author et al” in the references, use a custom .bst file.

I downloaded the original version of the file there and change the FUNCTION {format.names} part by

INTEGERS { max.num.names.before.forced.et.al num.names.shown.with.forced.et.al }

FUNCTION {format.names}
{ 's :=
  #1 'nameptr :=
  #5 'max.num.names.before.forced.et.al :=
  #1 'num.names.shown.with.forced.et.al :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
      nameptr #1 >
        { nameptr num.names.shown.with.forced.et.al #1 + =
          numnames max.num.names.before.forced.et.al >
            { "others" 't :=
              #1 'namesleft :=
            { skip$ }
          namesleft #1 >
            { ", " * t * }
            { t "others" =
                { " " * "et~al." emphasize * }
                { numnames #2 >
                    { "," * }
                    { skip$ }
                  " and " * t *
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=

This allows maximum five authors before it switches to “First Author et al” mode. These numbers are defined in lines with 'max.num.names.before.forced.et.al := and 'num.names.shown.with.forced.et.al :.

I put this new .bst file in the folder of my .tex file and called it in the style command: \bibliographystyle{unsrtnat5}.

“Name Year” style

I used \citep{} with this configuration:

\bibpunct{ (}{)}{;}{a}{}{;}

Order of initials

To get Simpson H. instead of Homer Simpson I changes the .bst file line in the format.names function to :

{ s nameptr "{vv~}{ll~}{f.}{, jj}" format.name$ 't :=


There are nicer option with biblatex but since I’m still using bibtex I went into the .bst file and changed the formatting functions:

FUNCTION {format.url}
{ "" }
%%{ url empty$
%%    { "" }
%%    { new.block "URL \url{" url * "}" * }
%%  if$

FUNCTION {format.doi}
{ "" }
%%{ doi empty$
%%    { "" }
%%    { new.block "\doi{" doi * "}" * }
%%  if$


Changing the font

By default, Beamer uses a sans-serif font. It looks a bit harsh. I find the Palatino font easier on the eye. To switch to serif font and choose the Palatino, I add at the beginning of the document:


Section slides

To introduce sections, Beamer can automatically insert slides. These automated slides can be defined with:

      \structure{\Large\bf \insertsection}
      \structure{\large \insertsubsection}


I tend to use the minimalist default theme, remove the navigation bar but add slide number:

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[page number]

For an important presentation, I could use a more fancy theme, such as the Metropolis theme or the Execushares one. Eventually I would like to mix and customize these two (see current state there).

Background image

For the acknowledgment slide or for more informal presentations, I sometimes want to use a specific image as background for a slide.


Backup slides

To add extra slides at the end of the presentation without increasing the total number of slides displayed: