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 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 ?

share|improve this question

1 Answer 1

up vote 16 down vote accepted

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

share|improve this answer
    
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
3  
beautifully indented code :) +1 –  cmhughes Nov 17 '12 at 1:08

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.