2

Similar to this question: How to make pgfplots vertical labels have proper hyperref erence box? Except, that I am trying to get hyperref working with angled rotated x-axis labels: plot plot2

Got it working, thanks to @Jake.

fin

Update: Got it sorted with href. Thanks.

\newcommand{\nenameref}[1]{\noexpand\nameref{{#1}}}
\newcommand{\nehref}[1]{\noexpand\href{{#1}}}
\begin{tikzpicture}
\def\labellist{{"\nehref{www.google.com}{google}","\nenameref{testtwo}","reallylonglabel"}},
Frank Zafka
  • 1,189

1 Answers1

1

You can wrap all the tick labels in a rotatebox by using the \ticklabel key (instead of \ticklabels) and defining the references in a list with \noexpand so they survive all the processing. You should use an anchor that is equivalent to the rotation of the labels, to avoid getting an offset:

\documentclass{article}
\usepackage{hyperref}
\usepackage{rotating}
\usepackage{pgfplots}
\usepackage{nameref}
\usepackage{graphicx}
\begin{document}
\section{the beginning}
This is a test.\label{test} \\
This is \nameref{test}. 
\section{second section}
Test two \label{testtwo}

\newcommand{\nenameref}[1]{\noexpand\nameref{{#1}}}
\begin{tikzpicture}
\def\labellist{{"\nenameref{test}","\nenameref{testtwo}","reallylonglabel"}},
\begin{axis}[xtick={1,...,3},
  xticklabel={\pgfmathparse{\labellist[\tick-1]}\rotatebox{65}{\pgfmathresult}},
  x tick label style={anchor=65}]
\addplot+[only marks,
  error bars/.cd,
    y dir=both,
    y explicit,
    error bar style={line width=2pt},
    error mark options={
      rotate=90,
      red,
      mark size=8pt,
      line width=2pt}
]
coordinates {
(3,1) +- (0,0.35665)
(2,1) +- (0,-0.35048)
(1,1) +- (0,0.150255)
};
\end{axis}
\end{tikzpicture}
\end{document}

pgfplots with rotate tick labels

David Carlisle
  • 757,742
Jake
  • 232,450