0

I would like to display a common legend for a groupplot like this:

\documentclass[crop]{standalone}

\usepackage[svgnames]{xcolor} \usepackage{pgfplots} \usepgfplotslibrary{groupplots} \usepackage{hyperref}

\hypersetup{}

\begin{document}

\begin{tikzpicture} \begin{groupplot}[ group style={ {group size=1 by 1}}, legend entries={A, B}, legend columns=2, legend to name=grouplegend]

\nextgroupplot[title=One]
\addplot+[color=Blue] coordinates {(0,0) (1,1) (2,2)};
\addplot+[color=Red] coordinates {(0,2) (1,1) (2,0)};

\end{groupplot}

\node (l1) at ($(group c1r1.south)$) [below, yshift=-2\pgfkeysvalueof{/pgfplots/every axis title shift}] {\ref{grouplegend}};

\end{tikzpicture}

\end{document}

As seen in the result, the legend contains a reference to the figure (hyperref of course producing a box around it). Is there a way to disable this reference?

enter image description here

hfhc2
  • 852

1 Answers1

0

With this post Disable hyperref link for single footnote, I tried this:

\newcommand\blref[1]{%
  \begin{NoHyper}%
    \ref{#1}
  \end{NoHyper}%
}

The complet code

\documentclass[crop]{standalone}

\usepackage[svgnames]{xcolor} \usepackage{pgfplots} \pgfplotsset{compat=1.18}%<-- added \usepgfplotslibrary{groupplots} \usepackage{hyperref}

\hypersetup{} \newcommand\blref[1]{% \begin{NoHyper}% \ref{#1} \end{NoHyper}% } \begin{document}

\begin{tikzpicture} \begin{groupplot}[ group style={ {group size=1 by 1}}, legend entries={A, B}, legend columns=2, legend to name=grouplegend]

\nextgroupplot[title=One]
\addplot+[color=Blue] coordinates {(0,0) (1,1) (2,2)};
\addplot+[color=Red] coordinates {(0,2) (1,1) (2,0)};

\end{groupplot}

\node (l1) at ($(group c1r1.south)$) [below, yshift=-2\pgfkeysvalueof{/pgfplots/every axis title shift}] {\blref{grouplegend}};

\end{tikzpicture}

\end{document}

pascal974
  • 4,652
  • Well, If I have a larger grid of say 3x3 groups, I would like to place the legend at a specified position outside of the grid, which is greatly helped based on the legend to name tool. For a single plot I would indeed use the basic approach instead. – hfhc2 Feb 15 '23 at 13:17
  • A new answer, maybe this is what you wanted. – pascal974 Dec 22 '23 at 13:28