0

I have a pgfplot (groupplot) with a horizontal legend. How can I align the legend texts at the bottom? You can see an example in the picture below. The letters a and b are not on the same bottom line.

MWE:

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{pgfplots.groupplots,plotmarks,arrows.meta,matrix}

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
    \begin{groupplot}[group style={group size=1 by 1,},
        legend columns=2,]
        \nextgroupplot
            \addplot[mark=none]coordinates {
                (0,0) (10,50) (20,100) (30,200) };
            \addplot[mark=none]coordinates {
             (50,600) (60,800) (80,1000)};
            \legend{a,b};
    \end{groupplot}
\end{tikzpicture}
\end{document}

enter image description here

5
  • I found a workaround with placing \vphantom in the legend text; \legend{a\vphantom{b},b};. Anyways, it would be great to have a cleaner solution.
    – Steradiant
    Sep 6, 2023 at 7:39
  • off-tošis: why you use group plot of you have only one diagram?
    – Zarko
    Sep 6, 2023 at 7:43
  • Because I have multiple plots in my document, some actually have multiple subplots. I want to use the same environment for all my plots throughout the document to ensure, that they all look the same (especially regarding the size)
    – Steradiant
    Sep 6, 2023 at 7:47
  • The same environment of plots you can define by \\pgfplotsset ...
    – Zarko
    Sep 6, 2023 at 7:49
  • I know, but the sizes are different for groupplots and normal plots if I set the width=x cm. If I use the same environment, hence, groupplots also for single plots, I get same sized plots.
    – Steradiant
    Sep 6, 2023 at 8:14

1 Answer 1

0

See, if the following solution is what you after:

enter image description here

MWE (without using group plot, but with global defined legend style):

\documentclass[margin=3mm]{standalone}
%    \usepackage{tikz}  it is loaded by pgfplots

\usepackage{pgfplots}
\pgfplotsset{           compat = 1.18,
           legend style={nodes = {anchor=base, yshift=-0.5ex}},
/tikz/every even column/.style = {column sep=1em}   % if you liked
             }

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
legend columns = 2
            ]
\addplot[mark=none]coordinates {
    (0,0) (10,50) (20,100) (30,200) };
\addplot[mark=none]coordinates {
 (50,600) (60,800) (80,1000)};
    \legend{a,b};
 \end{axis}
    \end{tikzpicture}
\end{document}

This solution works also with group plots, if you prefer to use it even at single diagram. I also took a liberty and a wee bit change legend style :-)

You must log in to answer this question.

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