12

How can I rotate the link of a text in a node. Here is my MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage{hyperref}

\begin{document}

\begin{tikzpicture}
\node (rect) [rectangle, fill=blue, rotate=90] {\hyperlink{rec}{Damn it!}};
\end{tikzpicture}

\end{document}

I can get rid of the box surrounding the text obviously but this does not solve my problem.

Additionally, any way that I can link the node itself, that is the shape such as a rectangle, circle, etc?


Thanks all for the answers but I think my MWE was to minimal. To answer the answers below:

  • with \rotatebox the shape changes,
  • and I cannot hyperlink the whole environment because I have other nodes.

So here is the new MWE: I would like the shape as in "shape ok" but the link as in "link ok" box; and just rotate and link one of the nodes.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzstyle{block} =[fill=red!20, rectangle, minimum height=1cm, minimum width=2cm]

\begin{document}

\begin{frame}
\makebox[\textwidth][c]{%
\begin{tikzpicture}%
\node (rect1) [block, rotate=90] {\hyperlink{link}{shape ok}};
\node (rect2) [block, above=2cm of rect1] {\rotatebox{90}{\hyperlink{link}{link ok}}};
\end{tikzpicture}}%
\end{frame}

\end{document}
doncherry
  • 54,637
jejuba
  • 1,471
  • 2
  • 13
  • 21

3 Answers3

8

This has slightly different link spacing, but it works: Just put the entire rotated content in the \hyperlink:

\documentclass{article}
\usepackage{tikz}
\usepackage{hyperref}

\begin{document}

\hyperlink{rec}{%
\begin{tikzpicture}
\node (rect) [rectangle, fill=blue, rotate=90] {Damn it!};
\end{tikzpicture}%
}

\end{document}

doncherry
  • 54,637
  • When i use \rotatebox, the shape of the node changes. ANy idea why? – jejuba Oct 03 '11 at 00:21
  • No, no idea, sorry. I came to my answer by logic only, I usually draw and rotate few things only. – doncherry Oct 03 '11 at 08:39
  • OK, thanks. I'll keep looking and post something if I find an answer. I guess I could create some kind of invisible node, over that one, with just the link... – jejuba Oct 03 '11 at 17:17
6

You can use \rotatebox{90}{...} (provided by graphicx) instead of the rotate=90 option:

\documentclass{article}
\usepackage{tikz}% http://ctan.org/pkg/pgf
\usepackage{hyperref}% http://ctan.org/pkg/hyperref

\begin{document} \begin{tikzpicture} \node (rect) [rectangle, fill=blue] {\rotatebox{90}{\hyperlink{rec}{Hello!}}}; \end{tikzpicture}

\end{document}

Rotated node and hyperlink

Werner
  • 603,163
6

For this specific effect you could also use adjustbox in one of the following ways. As a nice side-effect you can even use verbatim content.

\documentclass{article}
\usepackage{xcolor}
\usepackage{adjustbox}
\usepackage{hyperref}

\begin{document}

\adjustbox{angle=90,margin=2pt,bgcolor=blue}{\hyperlink{rec1}{Damn it!}}
%
\hyperlink{rec2}{\adjustbox{angle=90,margin=2pt,bgcolor=blue}{Damn it!}}
%
\adjustbox{angle=90,margin=2pt,bgcolor=blue,precode=\hyperlink{rec3}}{Damn it!}
%
\newcommand{\bluehyperlink}[1]{%
    \adjustbox{angle=90,margin=2pt,bgcolor=blue,precode=\hyperlink{#1}}%
}%
\bluehyperlink{rec}{Damn \verb+$%^!+}
\end{document}

Results

Martin Scharrer
  • 262,582