# Using subfigure and creating two rows of figures?

I am trying to get two rows with two figures in each row using subfigure, but I keep getting errors for this.

\documentclass[demo]{article} % remove 'demo' option in real document
\usepackage{graphicx,subcaption}
\begin{document}
\begin{figure}

\begin{subfigure}[0.45\textwidth]
\includegraphics[width=\textwidth]{long_pneumonic.jpg}
\caption{Pre-vaccination susceptible and infected
population$\alpha=0.000015, \beta=0.0027, \delta=.002, \sigma=1/3, \Delta=3/4, r=1/5$.}
\end{subfigure}
\begin{subfigure}{0.45\textwidth}
\includegraphics[width=\linewidth]{long_pneumonic2.jpg}
\caption{Transient loops of the infected and susceptible population
changes.}
\end{subfigure}
\begin{subfigure}{0.45\textwidth}
\includegraphics[width=\linewidth]{long_pneumonic3.jpg}
\caption{The population of susceptible individuals and infected
individuals over a period of 1500 days post-vaccination.
$\alpha=0.000015, \beta=0.0027, \delta=.002, \sigma=1/3, \Delta=3/4, r=1/5$.}
\end{subfigure}
\begin{subfigure}{0.45\textwidth}
\includegraphics[width=\linewidth]{long_pneumonic4.jpg}
\caption{[A graph showing the rise and decrease of pneumonic plague
victims leading to increasing amounts of infected with each recurrence
post-vaccination.}
\end{subfigure}
\caption{Graphs comparing and contrasting the same parameters examining the
dynamics of the susceptible and infected populations pre and post
vaccinations.}
\end{figure}
\end{document}

• Welcome to TeX.SE. I suggest you start by replacing \begin{subfigure}[0.45\textwidth] with \begin{subfigure}{0.45\textwidth} in the first subfigure environment. – Mico Feb 16 at 6:47
• I've taken the liberty of adding some code at the top and bottom of the code block in order to make it compilable. Feel free to revert. – Mico Feb 16 at 6:59
• Doing that, it stops and tells me there is an error in that line – Ian Lynch Feb 16 at 7:00
• And what might that error be? (Sorry, my psychic skills are badly underdeveloped...) – Mico Feb 16 at 7:10
• ! Missing number, treated as zero. <to be read again> } l.544 \begin{subfigure}[t]{0.45\linewidth} ? – Ian Lynch Feb 16 at 7:29

You wrote,

I keep getting errors

You didn't mention which errors you are getting, but I can only assume that they are caused by the line

\begin{subfigure}[0.45\textwidth]


at the start of the first subfigure environment. Change this line to

\begin{subfigure}{0.45\textwidth}


i.e., replace the square brackets with curly braces, and the immediate problem should be fixed. (Note that the other three \begin{subfigure}{0.45\textwidth} directives are already correct.) By the way, I'm assuming that your documents loads the subcaption package, not the obsolete and deprecated subfigure package.

In addition to fixing the syntax error, you may also want to "spruce up" the appearance of the figure. E.g., increase the horizontal separation between the subfigures, increase the space between the two rows of subfigures, and switch from full justification to centering for the captions of the four subfigures.

\documentclass[demo]{article} % remove 'demo' option in real document
\usepackage{graphicx,subcaption,ragged2e}
\begin{document}

\begin{figure}
\captionsetup[subfigure]{justification=Centering}

\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\textwidth]{long_pneumonic.jpg}
\caption{Pre-vaccination susceptible and infected population. $\alpha=0.000015$, $\beta=0.0027$, $\delta= 0.002$, $\sigma=1/3$, $\Delta=3/4$, $r=1/5$.}
\end{subfigure}\hspace{\fill} % maximize horizontal separation
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\linewidth]{long_pneumonic2.jpg}
\caption{Transient loops of the infected and susceptible population changes.}
\end{subfigure}

\bigskip % more vertical separation
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\linewidth]{long_pneumonic3.jpg}
\caption{The population of susceptible individuals and infected individuals over a period of 1500 days post-vaccination.
$\alpha=0.000015$, $\beta=0.0027$, $\delta=0.002$, $\sigma=1/3$, $\Delta=3/4$,
$r=1/5$.}
\end{subfigure}\hspace{\fill} % maximize horizontal separation
\begin{subfigure}[t]{0.45\textwidth}
\includegraphics[width=\linewidth]{long_pneumonic4.jpg}
\caption{A graph showing the rise and decrease of pneumonic plague victims leading to increasing amounts of infected with each recurrence post-vaccination.}
\end{subfigure}

\caption{Graphs comparing and contrasting the same parameters examining the  dynamics of the susceptible and infected populations pre and post  vaccinations.}

\end{figure}
\end{document}