Fortunately the subcaption package in LaTeX allows us to do this easily. (The subfigure and subfig packages have been deprecated, so it's best to use subcaption instead.)
How can you make more than one image or table be part of a LaTeX figure while still being able to create text captions for each?
Using the word clouds from my R word cloud tutorial, let's look at an example:
In order to make the figure containing the subfigures, we'll need to decide a few things first. Then it's just a matter of letting LaTeX know our preferences:
- The precise or proportional width of the subfigures
- The filenames
- The subcaptions
- How much horizontal or vertical space should be between subfigures
- The overall figure caption
We also need to let LaTeX know to use the caption and subcaption packages. The full code for the example image above is included below, and also in a gist.
\documentclass{article} \usepackage{graphicx} \usepackage{caption} \usepackage{subcaption} \begin{document} \begin{figure} \centering \begin{subfigure}{0.4\textwidth} % width of left subfigure \includegraphics[width=\textwidth]{rncalt.png} \caption{RNC} % subcaption \end{subfigure} \vspace{1em} % here you can insert horizontal or vertical space \begin{subfigure}{0.4\textwidth} % width of right subfigure \includegraphics[width=\textwidth]{dncalt.png} \caption{DNC} % subcaption \end{subfigure} \caption{Wordcloud of national conventions} % caption for whole figure \end{figure} \end{document}
For more information, this wikibooks article is useful.
--
This post is one part of my series on LaTeX.
No comments:
Post a Comment