2

This is my first post, so I hope I do everything right :)
I have the following problem:
Using pgfplots I create two graphs next to each other which have identical y-axes, but different x-axes. I want the x-axes to be aligned, and the y-axes to be of the same height, but due to the different labels on the x-axes, the second graph is shifted down. Is there a way to align the axes? Here is my code:

\documentclass[crop,10pt]{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}
\begin{document}%
    \fbox{
    \begin{tikzpicture}
    \begin{axis}[
    width=0.6\linewidth,
    height=5cm,
    xmin=0,xmax=1,ymin=0,ymax=1,
    ytick pos = left,
    xtick pos = left,
    enlargelimits=false,
    tick align = outside,
    xlabel={$|k|_{\parallel}$}
    ]
    \end{axis}
    \end{tikzpicture}}%
    \fbox{
    \begin{tikzpicture}
    \begin{axis}[
    width=0.30\linewidth,
    height=5cm,
    xmin=0,xmax=0.5,ymin=0,ymax=1,
    ytick pos = left,
    xtick pos = left,
    enlargelimits=false,
    tick align = outside,
    xlabel={Intensity}
    ]
    \end{axis}
    \end{tikzpicture}%
}%
\end{document}

The \fbox{} enironment was just set to see the boundaries. The right graph is in fact smaller than the left one due to the different label, though the y-axes do have the same length. When I use identical labels, everything is nicely aligned.
Any suggestions are appreciated.
Thanks in advance,
John

2

I would recommend using the groupplots library for this. It aligns the axes properly, makes sure the axes are synchronised in terms of the axis limits, and makes it easier to set styles that affect both axes simultaneously:

\documentclass[crop,10pt,margin=5mm]{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\begin{document}%
    \begin{tikzpicture}
    \begin{groupplot}[
        group style={
            group size=2 by 1
        },
        width=0.6\linewidth,
        height=5cm,
        xmin=0,xmax=1,ymin=0,ymax=1,
        ytick pos = left,
        xtick pos = left,
        enlargelimits=false,
        tick align = outside,
        xlabel={$|k|_{\parallel}$}
    ]
    \nextgroupplot
    \addplot {rnd};

    \nextgroupplot[
        width=0.30\linewidth,
        xmin=0,xmax=0.5,ymin=0,ymax=1,
        xlabel={Intensity}
    ]
    \addplot{rnd};
    \end{groupplot}
    \end{tikzpicture}%
\end{document}
  • That does the trick. Thank you for the fast help! – Janek Sep 3 '12 at 14:07

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.