pgf-tikz / pgfplots

pgfplots - A TeX package to draw normal and/or logarithmic plots directly in TeX in two and three dimensions with a user-friendly interface and pgfplotstable - a TeX package to round and format numerical tables. Examples in manuals and/or on web site.
http://pgfplots.sourceforge.net/
187 stars 33 forks source link

groupplots `trim axis group left` not compatible with `group name` #479

Open microlith57 opened 1 month ago

microlith57 commented 1 month ago

Currently, using /pgfplots/trim axis group left fails if the group name is redefined with /pgfplots/group/group name, which causes problems eg. when using remember picture in a document with multiple group plots (as in this case it is useful to rename the group).

Specifically, this line: https://github.com/pgf-tikz/pgfplots/blob/e4650af133358943881aee83e607f3567ff2d0a4/tex/generic/pgfplots/libs/tikzlibrarypgfplots.groupplots.code.tex#L117 hardcodes the group name as group, which is not always the case.

This can be worked around by setting /tikz/trim left={(custom name c1r1.south west)} instead, which has the desired effect.

Example:

\documentclass[a4paper]{article}

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

\begin{document}
\centering

\begin{tikzpicture}[trim axis group left,trim axis group right]
  \begin{groupplot}[
    group style={group size=2 by 2, group name=custom name},
    height=3cm,width=3cm
  ]
  \nextgroupplot
    \addplot coordinates {(0,0) (1,1) (2,2)};
  \nextgroupplot
    \addplot coordinates {(0,2) (1,1) (2,0)};
  \nextgroupplot
    \addplot coordinates {(0,2) (1,1) (2,1)};
  \nextgroupplot
    \addplot coordinates {(0,2) (1,1) (1,0)};
  \end{groupplot}
\end{tikzpicture}

\end{document}

yields

Package pgf Error: No shape named `group c1r1' is known.