4

I want to align subplots in a pgfplot.

with \matrix it is easy to align pictures. My problem is, that I need several rows with two columns/pictures and a last row with a picture over both columns.

Here the not working code illustrating what I wanted to do

\documentclass[a4paper,oneside,10pt]{scrreprt}

\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[USenglish]{babel}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{figure} [H]
    \centering
    \begin{tikzpicture}
        \matrix{
        \begin{axis}[width=0.45\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
        &
        \begin{axis}[width=0.45\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
        \\
        \begin{axis}[width=0.9\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
        \\  
        };
\end{tikzpicture}
\end{figure}


\end{document}

that's the unwanted result

enter image description here

and that's how I wanted it to look

enter image description here

I had a look at

  • Manual for Package pgfplots by Christian Feuersaenger
  • TikZ & PGF Manual by Till Tantau

but did not found a solution (maybe there is non)

Does anybody has a solution for doing it with /matrix (highly appreciated) or maybe another solution?

kind regards Benjamin

5

The \hspaces may need to be tweaked, but alignment issues are compounded by the fact that horizontal-axis labels (in some but not all cases) protrude beyond the bounding box of the graphs, and also because not all vertical -axis labels are same width (because of negatives). The underlying \stackon method is, by default, center aligned. If you think making it left-aligned might make things easier, \def\stackalignment{l} before you begin will accomplish it.

\documentclass[a4paper,oneside,10pt]{scrreprt}

\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[USenglish]{babel}
\usepackage{stackengine}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{figure} [H]
    \centering
\stackon[5pt]{%
    \begin{tikzpicture}
        \begin{axis}[width=0.9\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
\end{tikzpicture}
}{%
    \begin{tikzpicture}
        \begin{axis}[width=0.45\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
\end{tikzpicture}%
\hspace{5.5ex}%
    \begin{tikzpicture}
        \begin{axis}[width=0.45\textwidth,height=0.45\textwidth]
            \addplot {x};
        \end{axis}
\end{tikzpicture}
\hspace{1ex}%
}
\end{figure}


\end{document}

enter image description here

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.