2

I have the following code:

usepackage{subfigure,subcaption,caption}

    \begin{figure}[H]
        \centering
            \begin{subfigure}{0.32\textwidth}
                \centering
                \includegraphics[height=1.2in]{Canada.png}
                \caption{Canada}
            \end{subfigure}
            \begin{subfigure}{0.32\textwidth}
                \centering
                \includegraphics[height=1.2in]{US.png}
                \caption{United States}
            \end{subfigure}
            \begin{subfigure}{0.32\textwidth}
                \centering
                \includegraphics[height=1.2in]{UK.png}
                \caption{United Kingdom}
            \end{subfigure}
            ~
            \begin{subfigure}{0.32\textwidth}
                \centering
                \includegraphics[height=1.2in]{China.png}
                \caption{China}
            \end{subfigure}
            \begin{subfigure}{0.32\textwidth}
                \centering
                \includegraphics[height=1.2in]{India.png}
                \caption{India}
            \end{subfigure}
            \begin{subfigure}{0.32\textwidth}
                \centering
                \includegraphics[height=1.2in]{Brazil.png}
                \caption{Brazil}
            \end{subfigure}
        \caption{2010 - 2016\\ source: \citep{source}}
    \end{figure}

which gives the following error in line with the \begin{subfigure}...: "Missing number, treated as zero. Illegal unit of measure (pt inserted). I can't for the life of me understand whats wrong as I copied this from a previous project I created and just placed different graphics and added 2 more and changed the measurement of each subfigure to {0.32\textwidth} from the prior {0.45\textwidth}. Is there something functionally different about using 6 figures rather than 4? I don't see why there would be

1
  • 5
    The subfigure and the subcaption package are not compatible with each other. You should get an error message informing you about this. To fix this, remove the subfigure package from your preamble.
    – leandriis
    Mar 12, 2020 at 19:43

1 Answer 1

5

I addition to heeding @leandriis' advice and not loading the deprecated subfigure package, you may also want to get rid of all 7 \centering instructions and replace all 6 instances of height=1.2in with width=\textwith. Throw in a couple of \hfill directives on each row and a \bigskip directive between the rows, and you'll get this look:

enter image description here

The reason why I recommend against the height=1.2in option is that it provides no guarantee that the graphs will actually fit inside the available space.

\documentclass[demo]{article} % omit 'demo' option in real doc.
\usepackage{subcaption,graphicx,natbib}

\begin{document}
    \begin{figure}
    \begin{subfigure}{0.32\textwidth}
       \includegraphics[width=\textwidth]{Canada.png}
       \caption{Canada}
    \end{subfigure}\hfill
    \begin{subfigure}{0.32\textwidth}
       \includegraphics[width=\textwidth]{US.png}
       \caption{United States}
    \end{subfigure}\hfill
    \begin{subfigure}{0.32\textwidth}
       \includegraphics[width=\textwidth]{UK.png}
       \caption{United Kingdom}
    \end{subfigure}

    \bigskip % <-- new
    \begin{subfigure}{0.32\textwidth}
       \includegraphics[width=\textwidth]{China.png}
       \caption{China}
    \end{subfigure}\hfill
    \begin{subfigure}{0.32\textwidth}
       \includegraphics[width=\textwidth]{India.png}
       \caption{India}
    \end{subfigure}\hfill
    \begin{subfigure}{0.32\textwidth}
       \includegraphics[width=\textwidth]{Brazil.png}
       \caption{Brazil}
    \end{subfigure}
    \caption{2010--2016\\source: \citep{source}}
    \end{figure}
\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .