禁用 pgfplot 图例中的引用

禁用 pgfplot 图例中的引用

我想显示一个groupplot像这样的常见图例:

\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}

从结果中可以看出,图例包含对图形的引用(hyperref 当然会在其周围产生一个框)。有没有办法禁用此引用?

在此处输入图片描述

答案1

通过这篇文章禁用单个脚注的超链接,我尝试了这个:

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

完整代码

\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}

相关内容