Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm having trouble creating a 2x2 grid of subfigures. With this tex below, I get a 1x4 grid instead. I'm probably not understanding how the 0.5/textwidth worked, I presumed it used the parent's textwidth?

\begin{figure}[h!]
    \centering
    \begin{subfigure}[b]{0.5\textwidth}
          \centering
          \begin{subfigure}[b]{0.5\textwidth}
                  \centering
                  \includegraphics[width=\textwidth]{phone0018-A-crop.jpg}
                  \caption{Left cropped}
          \end{subfigure}
          ~
          \begin{subfigure}[b]{0.5\textwidth}
                  \centering
                  \includegraphics[width=\textwidth]{phone0018-A-shift.jpg}
                  \caption{Right shifted}
          \end{subfigure}
    \end{subfigure}
    ~
    \begin{subfigure}[b]{0.5\textwidth}
          \centering
          \begin{subfigure}[b]{0.5\textwidth}
                  \centering
                  \includegraphics[width=\textwidth]{phone0018-A-stereo.jpg}
                  \caption{Anaglypah of Stereo Pair}
          \end{subfigure}
          ~
          \begin{subfigure}[b]{0.5\textwidth}
                  \centering
                  \includegraphics[width=\textwidth]{phone0018-A-diff.jpg}
                  \caption{Difference of Stereo Pair}
          \end{subfigure}
    \end{subfigure}
    \caption{\texttt{phone0018.pgm} with $D_h = 10$}\label{fig:contrast}
\end{figure}
share|improve this question

1 Answer 1

The subfigure environment from the subcaption package takes all the same arguments as a minipage.

The minipage environment adds a small amount of horizontal space at the end of the environment, which you can remove by using a % after \end{minipage}, or in this case \end{subfigure}.

All I've done in the MWE below is replace ~ with %; you are correct about your description of \textwidth, it uses the parent value.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}

\begin{document}
\begin{figure}[h!]
    \centering
    \begin{subfigure}[b]{0.5\textwidth}
          \centering
          \begin{subfigure}[b]{0.5\textwidth}
                  \centering
                  \includegraphics[width=\textwidth]{phone0018-A-crop.jpg}
                  \caption{Left cropped}
          \end{subfigure}%
          \begin{subfigure}[b]{0.5\textwidth}
                  \centering
                  \includegraphics[width=\textwidth]{phone0018-A-shift.jpg}
                  \caption{Right shifted}
          \end{subfigure}
    \end{subfigure}
    \begin{subfigure}[b]{0.5\textwidth}
          \centering
          \begin{subfigure}[b]{0.5\textwidth}
                  \centering
                  \includegraphics[width=\textwidth]{phone0018-A-stereo.jpg}
                  \caption{Anaglypah of Stereo Pair}
          \end{subfigure}%
          \begin{subfigure}[b]{0.5\textwidth}
                  \centering
                  \includegraphics[width=\textwidth]{phone0018-A-diff.jpg}
                  \caption{Difference of Stereo Pair}
          \end{subfigure}
    \end{subfigure}
    \caption{\texttt{phone0018.pgm} with $D_h = 10$}\label{fig:contrast}
\end{figure}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.