2

I use the sloped option to place slanted nodes along arrows in tikz. Now if that text contains clickable references with the hyperref package, they are not sloped. The text and the link are not aligned. Is there any way to rotate them too? Is this a bug in tikz?

These answers here don't help because I don't know the angle of rotation. It is computed by tikz.

Here is the minimal non working example for me:

\section{abc}\label{s:a}
One section
\section{def}\label{s:b}
Another section

\begin{tikzpicture}
  \node[rectangle, fill] (one) {} ;
  \node[rectangle, fill, right=5cm of one,yshift=3cm] (two) {};
  \path (one) edge[-,bend right=-31, near start] node[sloped,above] {\ref{s:a}~~~\ref{s:b}} (two);
\end{tikzpicture}

Result: The link for the two sits below the two, because the linkbox is not sloped.

Thomas
  • 1,927
  • 3
    Could you edit your question to include the code for a small example document that demonstrates the issue? – Jake May 27 '14 at 09:42

1 Answers1

3

Don't use sloped and above but rotation and shifting instead, because the problem comes with it.

Edit : with one unique command :

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{hyperref}
%\usepackage[colorlinks]{hyperref}
\usetikzlibrary{calc}


\makeatletter
\newcommand{\Hyp}[4][.5]{%
    \draw #2 -- #3
    let \p1 = ($ #3 - #2 $)
        in 
    \pgfextra{%
        \pgfmathparse{90-atan2(\x1,\y1)}
        \xdef\@ngle{\pgfmathresult}
    }
    node[pos=#1,shift={(\@ngle+90:8pt)}]
              {\rotatebox{\@ngle}{#4}}
    }
\makeatother

\begin{document}


\section{abc}\label{s:a}
One section
\section{def}\label{s:b}
Another section

\begin{tikzpicture}
\node[fill] (A) at (0,0)  {} ;
\node[fill] (B) at (50:4) {}  ;
\node[fill] (C) at (150:6) {}  ;

\Hyp{(A)}{(B)}{\ref{s:a}~~~\ref{s:b}} ;
\Hyp{(C)}{(A)}{\ref{s:a}~~~\ref{s:b}} ;

\end{tikzpicture}
\end{document}
Tarass
  • 16,912
  • I'm on the run, but what happens if you have two or more hyperrefs in your node? – Thomas May 27 '14 at 12:34
  • See my new answer. – Tarass May 27 '14 at 14:04
  • @Thomas still running ? ;-) is the answer convinient ? – Tarass May 28 '14 at 18:46
  • Thanks for your answers, but they more or less replicate what was in the answers I already linked. See my new example. – Thomas May 30 '14 at 06:45
  • I updated my answer, don't use sloped. One can make a newcommand to avoid repetitive command. – Tarass May 30 '14 at 10:13
  • In the contrary, in the answer you are pointing, there is no sloped tag and the box is rotated by 90. As you notice, this technic is not compatible with sloped directly. On has to avoid sloped by a fake. – Tarass May 30 '14 at 11:45
  • Your solution won't work for me because I don't know the angles in advance and I can't compute them. The minimal example is stripped down but in the actual application this is a more complex figure with many automatically computed paths that are bent in various ways. – Thomas May 30 '14 at 11:50
  • Change the place of nodes one and two, but don't touch the drawing command, the drawing will follow. it computes the angle by itself. – Tarass May 30 '14 at 12:02
  • As you can see, in my new edit, you don't have to make any calculation. – Tarass May 30 '14 at 13:48
  • I varied my minimal example to illustrate the bent path. I appreciate your effort, but essentially you are working around the bug / missing feature in tikz by computing the angles from the coordinates. – Thomas May 30 '14 at 16:52
  • It produces a straight line between the 2 nodes, what is the difference with the image produced by my way. You notice that sloped can't slope at link but you insist to use it. You should ask someone to make hypererf package sloped compatible, otherwise you have to fake. If the path is a straight line, use my solution, if the path is more complex I can adapt the solution for a general path but with the same thechnic: without sloped. – Tarass May 30 '14 at 17:00
  • It's not a tikz's bug, but a hyperref package law that draw a vertical-horizontal oriented rectangle regardless with the orientation of the text inside. – Tarass May 30 '14 at 17:04