3

I am using groupplots to display 12 plots in 2 columns and 6 rows. The two plots in each row are related to some method, and I want to specify the method name in the title. The problem is, that groupplots offers only labeling each plots, not multiple plots at once.

My current solution is to label the first plot in the row. The problem is that the title is aligned according to that first plot. Sometimes the title is wider than the plot and it looks weird.

The MWE is the following:

\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.12}

\begin{document}
    \begin{tikzpicture}
        \begin{groupplot}[
            group style={
                group size=2 by 2,
                vertical sep=2cm,
            },
            height=5cm,
            width=5cm,
        ]

        % Row 1
        \nextgroupplot[title=Some very long title]
        \addplot coordinates {(0,1) (1,0)};
        \nextgroupplot
        \addplot coordinates {(0,1) (1,0)};

        % Row 2
        \nextgroupplot[title=Another long title] 
        \addplot coordinates {(0,1) (1,0)};
        \nextgroupplot
        \addplot coordinates {(0,1) (1,0)};

        \end{groupplot}
    \end{tikzpicture}
\end{document}

The current output is the following:

enter image description here


The desired output would be (the title in each row is centered):

enter image description here

1

1 Answer 1

3

You can name your group with group name (default name is group) and put the nodes yourself.

\node[anchor=south] at ($(my plots c1r1.north east)!0.5!(my plots c2r1.north west)$){Some long title};
        \node[anchor=south] at ($(my plots c1r2.north east)!0.5!(my plots c2r2.north west)$){Another long title};

Code:

\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.12}

\begin{document}
    \begin{tikzpicture}
        \begin{groupplot}[
            group style={
                group name=my plots,
                group size=2 by 2,
                vertical sep=1cm,   %%<--------- adjust this as suitable
            },
            height=5cm,
            width=5cm,
        ]

        % Row 1
        \nextgroupplot%[title=Some very long title]
        \addplot coordinates {(0,1) (1,0)};
        \nextgroupplot
        \addplot coordinates {(0,1) (1,0)};

        % Row 2
        \nextgroupplot%[title=Another long title]
        \addplot coordinates {(0,1) (1,0)};
        \nextgroupplot
        \addplot coordinates {(0,1) (1,0)};

        \end{groupplot}
        \node[anchor=south] at ($(my plots c1r1.north east)!0.5!(my plots c2r1.north west)$){Some long title};
        \node[anchor=south] at ($(my plots c1r2.north east)!0.5!(my plots c2r2.north west)$){Another long title};
    \end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .