5

PGFPlots and hyperref don't seem to play well together for vertical text. For example, the ylabel (which is vertical) shows its hyperref box in the middle of nowhere instead of at the position and direction of the vertical label.

Does anybody know a workaround?

(Note two things: the hyperref box works well for rotatebox and for horizontal labels)

wrong vertical label

\documentclass{article}
\usepackage[]{hyperref}
\usepackage[]{pgfplots}  
\begin{document}
\rotatebox{90}{\href{http://www.google.com}{hello}}bye
\newline
\begin{tikzpicture} 
\begin{axis}[xlabel = {\href{http://www.google.com}{Time}},  ylabel = {\href{http://www.google.com}{Length}}] 
\end{axis}
\end{tikzpicture}
\end{document}

EDIT: Although Jake's answer (and Martin's) does the job, the problem persists for "units" part of the label. (I should have posted the full problem in my question instead of a simplification). As in the picture and code below, see how it seem not trivial to rotate the units part and also make it appear the expected location (after the end of the word "Length"):

units with link not rotated

\documentclass{article}
\usepackage[]{hyperref}
\usepackage[]{pgfplots}
\usepackage[]{tikz}
\usepgfplotslibrary{units}
\begin{document}
A plot with units:\newline
\begin{tikzpicture}
\begin{axis}[y label style={rotate=-90}, x unit = {\href{http://www.google.com}{\mathrm{s}}}, y unit = {\href{http://www.google.com}{\mathrm{m}}}, xlabel = {Time}, ylabel = {\rotatebox{90}{Length}}, title = {Axis}]
\end{axis}
\end{tikzpicture}
\end{document}

2 Answers 2

3

You can rotate the label in pgfplots by using y label style={rotate=-90} to get the hyperref box right, and then provide the label using a rotatebox. With this workaround, the hyperref box has the correct size and placement.

(I also added the \pgfplotsset{compat=1.3}, which improves the placement of the axis labels. It's not necessary for the solution, though)

\documentclass{article}
\usepackage[]{hyperref}
\usepackage[]{pgfplots}
\pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture} 
\begin{axis}[
  xlabel = {\href{http://www.google.com}{Time}},
  ylabel = {\rotatebox{90}{\href{http://www.google.com}{Length}}},
  y label style={rotate=-90}
] 
\end{axis}
\end{tikzpicture}
\end{document}

pgfplots axis with vertical hyperref links


In order to make this work with the units library, you can redefine one of the units library's macros that takes care of assembling the label and unit. The following code checks whether we're defining the label for the y axis, and if we are, it encloses the whole label string (i.e. label and unit) in a rotatebox:

\documentclass{article}
\usepackage{hyperref}
\usepackage{pgfplots}
\usepgfplotslibrary{units}

\makeatletter
\def\pgfplots@label@units#1{
    \if#1y\rotatebox{90}{\fi%
    \pgfkeysgetvalue{/pgfplots/#1label}{\pgfplots@loc@TMPa}%
    \pgfplots@loc@TMPa\space\pgfplots@label@units@@{#1}%
    \if#1y}\fi
}
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{axis}[y label style={rotate=-90},
  x unit = {\href{http://www.google.com}{\mathrm{s}}},
  y unit = {\href{http://www.google.com}{\mathrm{m}}},
  xlabel = {Time}, ylabel = {Length}, title = {Axis}]
\end{axis}
\end{tikzpicture}
\end{document}

linked unit

2
  • great works for answer of the question. However, I should have posted my full problem. Which was the case where the hyperlink was in the "y unit = {\\href{...}{m}". I'll edit the question just to add the picture.
    – alfC
    Mar 14, 2011 at 19:29
  • thanks, also if you add \pgfplotsset{y label style={rotate=-90}} in the header (e.g. before \makeatletter , you can use the axis environment as if this bug never existed.
    – alfC
    Mar 15, 2011 at 18:36
3

It seems that the underlying rotation code of PGF/TikZ doesn't rotate the extra href box hyperref creates. One workaround for this is to manually rotate it using \rotatebox and a \phantom content. The \phantom macro creates a box with the same dimensions as the content without printing anything. The \llap macro is then used to make it lap over the real content without pushing it to the side. Normally \rlap should be used but because of the 90degr turn it must be lapped to the left side instead.

\documentclass{article}
\usepackage[]{hyperref}
\usepackage[]{pgfplots}
\usepackage[]{graphicx}
\begin{document}
\rotatebox{90}{\href{http://www.google.com}{hello}}bye
\newline
\begin{tikzpicture}
    \begin{axis}[xlabel = {\href{http://www.google.com}{Time}},  ylabel = {%
             \llap{\rotatebox{90}{\href{http://www.google.com}{\phantom{Length}}}}%
             Length}] 
\end{axis}
\end{tikzpicture}
\end{document}

This isn't perfect. The resulting href box is not 100% at its correct horizontal position, but it is close and IMHO good enough.

Result

You might want sent this to the author of pgfplots and maybe also to the one of hyperref.

You must log in to answer this question.

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