Skip to content

LaTeX

A random collection of things archived for future use.

  • Tables Generator
    • Setting Default table style to Booktabs table style can be nice.
  • Equation Editor
    • For looking up rarely used symbols.
  • Include your figures/graphs in .pdf format instead of as a rasterised image (e.g, .png, .jpg).
  • \cite{}
  • \Cref and \cref (cleverref)
  • \footnote{\href{https://google.com}{Google}}, maybe even \url{https://google.com}, or a file in CWD \href{run:./file.txt}{File.txt}. See Overleaf - Hyperlinks.
  • \today, for the current date (day; updates every compile).
  • \num{200000} will print 200 000. Can use \usepackage[binary-units]{siunitx} for this.
  • Rounding commands
    • \newcommand{\roundup}[1]{\ensuremath{\lceil#1\rceil}}
    • \newcommand{\rounddown}[1]{\ensuremath{\lfloor#1\rfloor}}
  • \cdot for .
  • \mathbb{N} for Math blackboard bold font, e.g., ℕ.
  • \bot and \top for ⊤ and ⊥.
  • \textasciitilde for ~.
% Redefine subsubsection numbering to use letters. E.g., 1.1.a
\renewcommand{\thesubsubsection}{\thesubsection.\alph{subsubsection}}
% Set section number depth
\setcounter{secnumdepth}{3}
% Start numbering at 5, so first chapter/section is 5.1.1
\setcounter{section}{4}

Similar to Word (you probably don’t want this).

\usepackage{parskip}
\setlength{\parskip}{\baselineskip}%
\setlength{\parindent}{0pt}%

a), b), c)…

\begin{enumerate}[label=\alph*)]
\item Test.
\end{enumerate}

Create an enumeration with a custom pre- or postfix. Instead of 1, 2, 3, or A, B, C, you use FR1, FR2 (e.g., for functional requirements). Setting the ref= ensures that \cref{} is as intended (e.g., FR1, FR2). Of course if you use a reference, then you can easily click on it to view the item (e.g., requirement).

\crefformat{frlisti}{#2#1#3}
\newlist{frlist}{enumerate}{1}
\setlist[frlist]{label=(\bfseries FR\arabic*), ref=\bfseries FR\arabic*}
\begin{frlist}
\item\label{fr:distribute-work} The system must distribute the work...
\item\label{fr:varying-length} The system must support varying length...
\end{frlist}

Source: https://tex.stackexchange.com/a/229542

\begin{algorithm}[h]
\begin{algorithmic}[1]
\caption{$\mathbb{A}_{\text{ALG_NAME}}$}
\Require $X, A}$ \Comment{This is a comment}
\For{$x \in X$}
\If{$x = 0$}
\State \texttt{\textbf{continue}}
\EndIf
\EndFor
\State \Return $0$
\end{algorithmic}
\end{algorithm}

Use the minted package. AFAIK requires a certain environment (e.g., with Python) if you’re compiling your LaTeX locally.

\begin{minted}[breaklines, frame=lines, fontfamily=courier, fontsize=\scriptsize, linenos]{python}
def main():
print("Hello world!")
main()
\end{minted}

See: Overleaf - Theorems and proofs.

\theoremstyle{definition}
\newtheorem{definition}{Definition}
\newtheorem{proposition}{Proposition}
\newtheorem{claim}{Claim}
\begin{claim}\label{claim:runtime}
Claim about runtime here.
\end{claim}
\begin{proof}
Proof here.
\end{proof}

Basic.

\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance={5mm}, thick, main/.style = {draw, circle}]
\node[main] (left) {$v_1$};
\node[main] (below_right) [below right=of left] {$v_2$};
% \node[main, dotted, fill=lightgray!25] (x4) [below left=of x4c, xshift=0.6cm, yshift=0.2cm] {$x_4$};
% ↑ nice dotted border and lightgray background.
\draw[-] (left) -- (below_right);
% \draw[->] (left) -- node[midway, above, sloped, pos=0.4] {text here} (right);
% ↑ arrow with text.
\end{tikzpicture}
\caption{Caption here.}
\label{fig:...}
\end{figure}

Empty vertices.

\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance={15mm}, thick, main/.style = {draw, circle}]
\node[main] (1) {};
\node[main] (2) [right=of 1] {};
\node[main] (3) [right=of 2] {};
\node[main] (4) [right=of 3] {};
\node[main] (5) [right=of 4] {};
\node[main] (6) [right=of 5] {};
\draw (1) -- (2);
\draw [dotted] (2) -- (3);
\draw (3) -- (4);
\draw [dotted] (4) -- (5);
\draw (5) -- (6);
\end{tikzpicture}
\caption{Captiopn here...}
\label{fig:lines...}
\end{figure}

In a 1 column document, this will display two figures side-by-side (so each 50% of the width). Works with TikZ and other graphics (e.g., images).

\begin{figure}[h]
\centering
\begin{minipage}[b]{0.49\textwidth}
\centering
\begin{tikzpicture}[node distance={5mm}, thick, main/.style = {draw, rectangle, minimum size=8mm}]
\node[main] (11) {$v_{1, 1}$};
\end{tikzpicture}
\caption{Caption here...}
\label{fig:1}
\end{minipage}
\hfill
\begin{minipage}[b]{0.49\textwidth}
\centering
\begin{tikzpicture}[node distance={10mm}, thick, main/.style = {draw, circle}]
\node[main] (1) {$v_1$};
\end{tikzpicture}
\caption{Caption here...}
\label{fig:2}
\end{minipage}
\end{figure}

Graphic spans 1 column.

\begin{figure}[h]
\centering
\includegraphics[width=1\linewidth]{../graph.pdf}
\caption{Caption here}
\label{fig:graph}
\end{figure}

Graphic spans 2 columns.

\begin{figure*}[h]
\centering
\includegraphics[width=\textwidth]{../graph.pdf}
\caption{Caption here...}
\label{fig:overhead_analysis-dataset}
\end{figure*}