Skip to content

Instantly share code, notes, and snippets.

@hhromic
Last active January 3, 2019 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhromic/89d5e802c04c162c54730af99f432f39 to your computer and use it in GitHub Desktop.
Save hhromic/89d5e802c04c162c54730af99f432f39 to your computer and use it in GitHub Desktop.
Useful LaTeX snippets

Useful LaTeX Snippets

About Lenghts

From https://tex.stackexchange.com/a/16956:

\textwidth is generally the global width of the text area, while \columnwidth is the width of a column of text (it will be different from \textwidth when typesetting in two or more columns). However, inside a minipage, \textwidth will be set to the given argument along with \hsize, \columnwidth, and \linewidth (they will revert to the previous values at the end of the minipage because it forms a group). Note that \parbox doesn't reset \textwidth; the size is available as \linewidth.

The parameter \linewidth contains the line length inside a list (or derived) environment and it may change in a nested list (while \hsize, \textwidth and \columnwidth don't change).

When we have to specify a length depending on current conditions, we have to use the correct parameter. For example, the width of a figure should be specified in terms of \columnwidth in a figure environment and of \textwidth in a figure* environment; however this is done rarely when it's known that the document will be typeset in one column format. The same should be for a tabular* or tabularx environment.

Instead, when we need something centered with respect to a line in a list, we should use \linewidth.

Figures

Single figure:

\usepackage{graphicx}

\begin{figure}
 \centering
 \includegraphics[width=\columnwidth]{figures/figure}
 \caption{Figure caption.}
 \label{fig:figure-label}
\end{figure}

Multiple subfigures:

\usepackage{graphicx}
\usepackage[caption=false,font=footnotesize]{subfig}

\begin{figure}
 \captionsetup[subfloat]{farskip=0pt,nearskip=0pt}
 \centering
 \subfloat[Subcaption A\label{fig:figure-label:A}]{\includegraphics[width=0.49\columnwidth]{figures/A}}
 \hfill
 \subfloat[Subcaption B\label{fig:figure-label:B}]{\includegraphics[width=0.49\columnwidth]{figures/B}}
 \\
 \vspace{0.5em}
 \subfloat[Subcaption C\label{fig:figure-label:C}]{\includegraphics[width=0.49\columnwidth]{figures/C}}
 \hfill
 \subfloat[Subcaption D\label{fig:figure-label:D}]{\includegraphics[width=0.49\columnwidth]{figures/D}}
 \caption{Figure caption.}
 \label{fig:figure-label}
\end{figure}

Tables

  • The IEEEtran template requires the caption/label before the tabular environment.
  • The ACM template uses the caption/label after the tabular environment.
\usepackage{booktabs}

\begin{table}
 \caption{Table caption.}
 \label{tab:table-label}
 \centering
 \begin{tabular}{p{4.6em} c c c c}
  \toprule
  \textbf{Col A} & \textbf{Col B} & \textbf{Col C} & \textbf{Col D} & \textbf{Col E} \\
  \midrule
  Val 1A & Val 1B & Val 1C & Val 1D & Val 1E \\
  Val 2A & Val 2B & Val 2C & Val 2D & Val 2E \\
  Val 3A & Val 3B & Val 3C & Val 3D & Val 3E \\
  \midrule
  \textbf{Average} & \textbf{AvgB} & \textbf{AvgC} & \textbf{AvgD} & \textbf{AvgE} \\
  \bottomrule
 \end{tabular}
\end{table}

References

  • The IEEEtran bibliography style can be configured using special bib items.
\usepackage[noadjust]{cite}
\usepackage[hyphens]{url}
\usepackage[hidelinks]{hyperref}

\begin{document}
\bstctlcite{BSTcontrol}  % available in IEEEtran template

% towards the end
\fontsize{9.0pt}{10.0pt}
\selectfont
\bibliographystyle{IEEEtran}
\bibliography{refoptions,references}
\end{document}

The refoptions.bib file contains configuration for the IEEETran style:

@IEEEtranBSTCTL{BSTcontrol,
  CTLuse_article_number = "no",
  CTLuse_paper = "no",
  CTLuse_url = "no",
  CTLuse_forced_etal = "yes",
  CTLmax_names_forced_etal = "1",
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment