[Home] [GRP] [RES] [PUB] [ETC] [LEC] [S/W]
 

LaTeX Formatting Tips

Contents

Define Math formatting for vectors, matrices, etc., in the preamble, and use it consistently
 
Tables for article manuscripts
 
Captions for Tables and Figures
 
Text vs. Math vs. Italics
 
Make smart use of label and ref command pairs for cross-references
 
Dirac brackets
 
_________________________________________________________________________

Define Math formatting for vectors, matrices, etc., in the preamble, and use it consistently

Suppose you are finally ready to write your PhD thesis, or you decided to write a research paper, or a book, and you want to format symbols representing vectors in bold italic, and symbols representing matrices in sans serif. Bold math is easily accessible, for all sorts of glyphs, by loading the boldmath package and using the \bm{} command defined in the package. Math sans serif is accessible via \mathsf{}. However, it is not a good idea to type, for example, the inhomogeneous linear equation
 
Ax = b
 
in your LaTeX source document like this:
 

  \mathsf{A}\bm{x} = \bm{b}

Why is this not a good idea? Imagine this: After typing dozens or hundreds of equations, you decide—or someone else tells you—to change the formatting for matrices and vectors (and all sorts of other things)...? Now you would have to apply those changes everywhere you used your chosen formatting for matrices or vectors.

Instead, you want to define the formatting for different types of mathematical or physical objects in the preamble, so that you can change the notation easily throughout the document, simply by changing the definitions. For example, with the xelatex/lualatex + STIX2 setup described elsewhere on this site, I usually define in the preamble
 

  \newcommand{\vect}[1]{\bm{\mathit{#1}}} % boldface-italic for vectors 
  \newcommand{\bold}[1]{\bm{\mathrm{#1}}} % boldface-upright 
  \newcommand{\mat}[1]{\mathsf{#1}}       % upright-sans matrices 
  \newcommand{\matvec}[1]{\bm{\mat{#1}}}  % upright-bold-sans

The equation above would then be typed in the LaTeX source file like this:
 

  \mat{A}\vect{x} = \vect{b}

Now you can define the formatting in the preamble any way you like, and change it easily, if needed.
 
Back to Table to Contents
 
_________________________________________________________________________

Tables for article manuscripts

Table rule #1: Keep it simple
 
An example:
 
Table 1: My simple table.a

col. 1 headerb col. 2 headercol. 3 header
block 1 data label val. val.
val. val.
block 2 data label more stuff even more
block 3 data label so much
more stuff

a Table used to explain layout of a typical table appearing in a journal article.   b Another table footnote.
 
 
Use only 3 horizontal lines, one at the top of the table, one below the column header row(s), and one at the bottom of the table. No vertical lines, ever.
 
In my experience, journal production will always remove additional horizontal lines, along with any vertical space that you may have used to group data. Furthermore, if you try to center, for example, the ‘block 1 data label’ vertically with the block of 4 data points that follows, e.g. by using the \multirow{} command from the package with the same name, the result in the journal proofs will most likely be an incomprehensible mess. It’s always better to align a label for a block of data with the first row of data. The same considerations apply to table headers composed of multiple rows.
 
Table rule #2: If your table gets too wide, or too tall, consider transposing it
 
Table rule #3: In 10pt font, the table width should fit within a single column in the journal’s article layout, or within the text width (spanning both columns)
 
Table rule #4: If you can’t fit your data in the table, following rules #2 and #3, most likely your table should go in the Supporting/Supplementary Information of the article. There, you have more flexibility, including the use of the longtable environment and such.
 
The tabular code used for the table above is
 
\begin{tabular}{lrr}\hline 
  col.\ 1 header\textsuperscript{b} & col.\ 2 header & col.\ 3 header \\ \hline 
  block 1 data label  & val.        & val. \\ 
                      & val.        & val. \\ 
  block 2 data label  & more stuff  & even more \\ 
  block 3 data label  & so          & much \\ 
                      & more        & stuff \\ \hline 
\end{tabular}

Back to Table to Contents
 
_________________________________________________________________________

Captions for Tables and Figures

Captions for figures go below the figures
 
Captions for tables go above the tables
 
People tend to overload table captions with information, which will then be put into additional footnotes by journal production, thus likely messing up your existing table footnote labels. Keep table captions short, and put all additional information in the table footnotes. A footnote label may be attached to the table caption itself. See the example above. 
 
Back to Table to Contents
 
_________________________________________________________________________

Text vs. Math vs. Italics

  1. Use Math ($ ... $) only for Math, not for formatting italics.
     

  2. Consistently format things like cis, trans and so on in italics (\textit{cis} etc, not $cis$ !).
     

  3. If you have a physical quantity or a label in an equation that is typeset in Math (e.g. temperature T is typeset as $T$) it must be typeset the same everywhere, also in the text. T and T are different things.
     

  4. Avoid stuff like E$_a$ + 2 E$_b$ in your LaTeX code when in fact E is supposed to be E (e.g. an energy). In that case you use a single in-line Math construct such as $E_a + 2 E_b$.
     

  5. Sometimes we want to use text acronyms and such for subscripts and superscrips. Say, we define an isotropic chemical shift as δiso. Here, the LaTeX code is $\delta_{\text{iso}}$, with ‘iso’ short for ‘isotropic’. On the other hand, δiso, coded as $\delta_{iso}$, indicates a delta with three subscripts or alternatively a subscript i times s times o. Note that even δiso ($\delta_{\text{\textit{iso}}}$) looks different from δiso. In the former case the textual subscript is italic but the spacing/size may be different. Remember that there is a difference between $iso$ and \textit{iso}.
     
    The \text{...} command requires the amsmath package. \text{} is preferred over \mathrm{...} etc. You can use formatting inside \text{...}.
     

  6. Chemical formulas: load the chemformula package and use the \ch{} command. For example, \ch{H3O^+} is then typeset properly, unlike $H_3O^+$, which gives H3O+ with incorrect italic element symbols and terrible spacing. Instead of the chemformula macros, you can use H$_3$O$^+$, or even better, H\textsubscript{3}O\textsuperscript{+}, which is the safer way to format chemical formulas in BibTeX entries.

 
Back to Table to Contents
 
_________________________________________________________________________

Make smart use of label and ref command pairs for cross-references

Some tips:

  1. You can use \label{} and \ref{} for pretty much everything: Figures, Tables, Equations, Footnotes, Sections and Sub-(sub-sub-) Sections, Chapters, Book Parts, enumerated list items, and so forth. There is also \pageref{}. Given this powerful mechanism of having all such cross-references automatically updated, as you develop your manuscript, why would you not use it for all cross references? For example, I can reference item 2 in this list using \ref{item:use-descriptive-labels} after having placed \label{item:use-descriptive-labels} somewhere in that \item (which I just did).
     

  2. Choose descriptive labels. A label such as eq:3-1 may make sense at some point during the draft stage of a manuscript, but cross references have a tendency to change during the writing process. What used to be Equation 3.1 at some point may no longer be so at a later stage. Better use something like eq:schrodinger-time-dependent-initialdef. A good text editor, such as the one I’m using (GNU Emacs with the AucTeX add-on), will offer you a list of already defined labels to choose from when you type a \ref{} command, so having long descriptive labels should not be a problem. See also item 1. (Incidentally, I placed \label{item:use-label-ref-combos} at the end of that item and referenced it here as \label{item:use-label-ref-combos}.)
     

  3. On the topic of descriptive labels, I usually use eq: at the beginning of an equation label, and likewise fig:, tab:, sec:, for figures, tables, and sectioning, respectively. That way it’s easier to keep track of which label is for which kind of reference. Furthermore, some text editors can be configured to offer string completion only for labels beginning with eq: following the word Equation, for example.
     

  4. Blank space and special characters in labels should work, but why take the risk? Try to stick to ASCII characters and use dashes instead of blank spaces.

Back to Table to Contents
 
_________________________________________________________________________

Dirac brackets

I wrote a little style file, jobraket.sty, to help with typesetting Dirac brackets. The commands \sket{}, \sbra{}, \sbraket{}, and \sobraket{} (‘s’ for ‘small’) simply use delimiters | etc. that are the same size as the text’s base font.

Commands \ket{}, \bra{}, \braket{}, and \obraket{} use \left and \right for delimiters, but the macros adjust the vertical height of the arguments such that the delimiters are the same height throughout a bracket. This is useful for stuff like
 
Ψi(0)| Ψ j(0) = 0
(\braket{\Psi_i^{(0)}}{\Psi_j^{(0)}}=0$) or
 
Ĥi,j(1) = Ψ i(0)| Ĥ(1) |Ψ j(0)
($\scop{H}^{(1)}_{i,j} = \obraket{\Psi_i^{(0)}}{\scop{H}^{(1)}}{\Psi_j^{(0)}}$)

 
Back to Table to Contents
 
_________________________________________________________________________

© 2021 – 2024 J. Autschbach.