Is it possible to override the hyperref instruction of showing the references in a specific colour but only within the context of TikZ and pgfplots? The problem is that I am using legend to ref and \ref in a tikzpicture environment and the text of the legend becomes blue because of the hyperref global setting. I don't know how to force legend's text colour or even if that would work, but the solution I am looking for should be something that can be set globally in the preamble if possible.




      % \hypersetup{hidelinks} % jfbu's solution: Uncomment to get black text.
        group style={
          group size=2 by 1,},]
        \nextgroupplot[scale only axis,width=0.35\textwidth,height=0.35\textwidth,legend to name=grouplegend,]
          coordinates {(1,1) (2,2) (3,3)};
        \addlegendentry{Legend 1}
        \nextgroupplot[scale only axis,width=0.35\textwidth,height=0.35\textwidth]
          coordinates {(1,1) (2,2) (3,3)};
      \node (legend) at ($(group c1r1.south)!0.5!(group c2r1.south)$)
        [below, yshift=-3\pgfkeysvalueof{/pgfplots/every axis title shift}]
    \caption{The caption.}

enter image description here

jfbu's solution of placing \hypersetup{hidelinks} in the tikzpicture environment works by maintaining the links (I'm not interested in that) but showing the text in black. I'm looking for a way to achieve this globally though.

  • I have successfully used \hypersetup{hidelinks} inside a group (and environments create groups) in the past to address a similar issue. This cures the color problem by suppressing the links. I sort of remember having tried unsuccessfully to change the linkcolor using similarly other hyperref options locally.
    – user4686
    Commented Jul 30, 2013 at 15:01
  • Could you elaborate please? I am a beginner. Sorry.
    – sudosensei
    Commented Jul 30, 2013 at 15:04
  • 1
    Just insert \hypersetup{hidelinks} as the first thing inside your tikzpicture. Perhaps this will work.
    – user4686
    Commented Jul 30, 2013 at 15:12
  • @jfbu: Placing it inside the tikzpicture environment works. But I need something that can be set globally. @Jake: Yes, I'm editing my post now.
    – sudosensei
    Commented Jul 30, 2013 at 15:53
  • 2
    @sudosensei: You can set the option for all tikzpictures using \tikzset{ every picture/.style={ execute at begin picture=\hypersetup{hidelinks} } }
    – Jake
    Commented Jul 30, 2013 at 16:04

2 Answers 2


While scouring through the pgfplots manual, I happened to stumble upon a more elegant solution. Simply, instead of invoking a command that temporarily suspends hyperref before each picture, it is possible to just replace \ref{refname} with \pgfplotslegendfromname{refname}.

From the pgfplots manual on page 189:

This command poses an equivalent alternative for \ref{<name>}: it has essentially the same effect, but it does not create links when used with the hyperref package.

  • 1
    Oh, that's indeed much more elegant! Good find! You should accept this instead of my answer, so others can find the proper approach more easily.
    – Jake
    Commented Aug 16, 2013 at 6:27

You can disable the hyperref links in tikzpictures by using Stefan Kottwitz's approach from Selectively turn off hyperref links and wrapping it in execute at begin picture:

    every picture/.style={
        execute at begin picture={


You must log in to answer this question.

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