7

I want to have two subfigures in a figure. Each subfigure contains a simple pgfplot.

Here is what I have:

\documentclass[12pt]{article}

\usepackage{subcaption}
\usepackage{pgfplots}

\begin{document}

\begin{figure}
    \begin{subfigure}[a]{0.48\textwidth}
        \begin{tikzpicture}[scale=0.6, baseline]
            \begin{axis}[ybar]   
                \addplot+ coordinates { 
                    (1,2)
                };  
            \end{axis}
        \end{tikzpicture}
    \end{subfigure}
    \begin{subfigure}[b]{0.48\textwidth}
        \begin{tikzpicture}[scale=0.6, baseline]
            \begin{axis}[ybar]   
                \addplot+ coordinates { 
                    (1,2)
                };  
            \end{axis}
        \end{tikzpicture}
    \end{subfigure}
\end{figure}

\end{document}

The problem is that the second image is higher than the first one... I want to have both images at the same height.

Is there a way to do that ?

12

Use \begin{subfigure}[t]{0.48\textwidth} (Note the placement specifier [t])

\documentclass[12pt]{article}
%
\usepackage{subcaption}
\usepackage{pgfplots}
%
\begin{document}
%
\begin{figure}
\centering
    \begin{subfigure}[t]{0.48\textwidth}
      \centering
        \begin{tikzpicture}[scale=0.6, baseline]
            \begin{axis}[ybar]
                \addplot+ coordinates {
                    (1,2)
                };
            \end{axis}
        \end{tikzpicture}
      \caption{A subfigure}\label{fig:1a}
    \end{subfigure}
    \begin{subfigure}[t]{0.48\textwidth}
      \centering
        \begin{tikzpicture}[scale=0.6, baseline]
            \begin{axis}[ybar]
                \addplot+ coordinates {
                    (1,2)
                };
            \end{axis}
        \end{tikzpicture}
      \caption{Another subfigure}\label{fig:1b}
    \end{subfigure}
  \caption{Another figure}\label{fig:1}
\end{figure}
%
\end{document}

enter image description here

  • Oh god... I was sure that this was the index of the subfigures (a), b), c), ...). Thanks. – Baptiste Wicht Nov 16 '12 at 23:47
  • 4
    beautifully indented code :) +1 – cmhughes Nov 17 '12 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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