Some Useful Latex Tricks
This is a quick collection of some Latex tricks that I find useful, but keep forgetting. Hopefully these may be useful to others as well. Feel free to send me a message with any suggestions you would like to add here as well.
If you are new to Latex, much of these tips will probably not make much sense to you. In that case, and even for experienced users, I would recommend looking through the Overleaf Latex Guide. It has a wealth of information including nice examples for a broad array of Latex features. The tips outlined here are meant to document features that were a more obscure.
align
Environment
Selectively Numbering Lines in Often when writing long or complex equations in an align
environment it becomes convenient to split what would logically be a single line into multiple lines. You can selectively disable "labeling" or "tagging" a line with either the builtin \nonumber
command or the \notag
command from amsmath
.
A simple example is shown below:
\begin{align}
\label{eqn:simple_nhes_constrained}
\min\ \ & c_1 \frac{d g}{dt} + c_2 g \\
\text{subject to}\ \ & \frac{dT}{dt} = (gen - load_{net})
\frac{mass_{salt}}{C_{p, TES}} \nonumber\\
& T_{min} < T < T_{max} \\
& \frac{d g_i}{dt} < ramp_{max} \nonumber \\
& g_i \leq g_{max}
\end{align}
In this example, the second and forth line labels are suppressed, so only the other lines are labeled in the final output. \label
can still be used for refering to the labeled equations.

Fancy Horizontal Table Rules
The bookends
package provides several commands for handling horizontal rules within tables. Simply \usepackage{bookends}
and use \toprule
, \midrule
and \bottomrule
within the tabular
environment to add rules that have just the right weight and spacing.
\usepackage{bookends}
...
\begin{table}[!hbt]
\centering
\caption{System Physical Parameters}
\begin{tabular}{l c c l}
\toprule
Parameter & Value & Units & Description \\
\midrule
P1 & 0.95 & N/A & TES roundtrip efficiency \\
P2 & 0.8 & N/A & Turbine efficiency \\
P3 & 550 & MWth & SMR maximum capacity \\
P4 & 200 & MWth & SMR minimum capacity \\
P5 & NA & MWh & TES maximum capacity \\
\bottomrule
\end{tabular}
\label{tab:physical_parameters}
\end{table}

Handling sized brackets/parenthesis over multiple lines
To be added soon...
The handy phantom space
Every now and then it is handy to adjust the size of a line or other item in Latex even though the content doesn't really required the extra space. \vspace
often does the trick, but if the difficulty is within math mode then \vphantom
is often a better choice.
When the figure numbers don't line up right...
Try switching where \label
and \caption
are in figures and tables. It shouldn't make a difference, but somethimes it does.