# Wrong place for hyperref link in scaled tikz picture

I have a TikZ picture with a node containing a minipage with an itemize environment; each item is a hyperref to other sections of the document.

When scaling the image (for example with \begin{tikzpicture}[scale=.7, transform shape] I've a strange behavior: links in itemize are not in the right place: they present a somewhat vertical offset, as if they don't scale as the rest of image.

Here the MWE:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage[pdftex]{hyperref}
\begin{document}

Here something interesting\label{text:interesting-one}
\newpage

Here something interesting, too\label{text:interesting-two}
\newpage

and here there are very very interesting stuff\label{text:interesting-three}
\newpage

\newpage
Now the problem: links rectangles have some offset, making links unusable in case of long itemize

\begin{figure}[htb]
\begin{tikzpicture}[scale=.7, transform shape]
\node at (0,0) (mynode) {
\begin{minipage}{4cm}
\begin{itemize}
\end{itemize}
\end{minipage}
};
\end{tikzpicture}
\end{figure}
\end{document}


And here a snapshot of the problem

Note: This is evident using the default settings of hyperref package, which draws the red rectangle around links, but it took me some time to found it when only the text is coloured, i.e. when using \usepackage[linkcolor=blue,colorlinks=true]{hyperref}

-
A bug in tikz, it does not use the proper interface of pdfTeX for scaling (\pdfsave, \pdfsetmatrix, \pdfrestore). – Heiko Oberdiek Dec 14 '12 at 14:42

To be honest, it looks like you are looking for trouble by nesting all the problematic things into one place :) Don't use [pdftex] option for hyperref it's smart enough to decide. Also use \tikzmark for marking the points where you need rectangle around or use mdframed or something similar to frame it. Otherwise, you need to make sure that everything communicates with each other, no matter what which looks tedious and unnecessary.

An alternative

\documentclass[a4paper]{article}

\usepackage{hyperref}
\usepackage{graphicx}
\begin{document}

Here something interesting\label{text:interesting-one}
\newpage

Here something interesting, too\label{text:interesting-two}
\newpage

and here there are very very interesting stuff\label{text:interesting-three}
\newpage

\newpage
Now the problem: links rectangles have some offset, making links unusable in case of long itemize

\scalebox{0.7}{
\begin{minipage}{4cm}
\begin{itemize}
\end{itemize}
\end{minipage}
}
\end{document}


-
I really don't need frame around link, it is only a way to clearly show the problem. I need tikzpicture, because the itemize is in a 'legend' node in a big orgchart, thats why I've put it into my MWE. Anyway, your code works well: \scalebox{.7}{ \begin{tikzpicture} ... \end{tikzpicture} }. Thanks – cbe Dec 14 '12 at 14:55

## Fixing pgf

pdfTeX does not analyze the contents of \pdfliteral. Therefore it does not know the operators that might affect the current transfer matrix (save/restore/set matrix). Instead \pdfsave, \pdfrestore, \pdfsetmatrix should be used. Then pdfTeX can calculate the current transfer matrix and fix the rectangles for anchors and links.

Outdated:

I have written a patch for pgf that supports transformations (rotate/scale, no translate) via \pdfsetmatrix instead of \pdfliteral. The patch is added to package hopgf v1.1, currently available here and available on CTAN with the next update of my bundle.

The patch redefines \pgssys@invoke and scans the argument for q (save), Q (restore), and cm (set current matrix) operators and replaces them with \pdfsave, \pdfrestore, or \pdfsetmatrix. The latter case only happens, if the translate coordinates are zero. Primitive \pdfsetmatrix does not support translation, because this can already be achieved by TeX, independently from the output driver.

In the meantime I have removed the patch, because it could not address all issues. The main problem is that the low level interfaces does not match: pgf operates on the full transfer matrix including translations, whereas \pdfsetmatrix does not support translations. Translations with TeX require boxes and that the contents of the material is available.

## Workaround via graphics/graphicx:

pdftex.def, the driver file for the package graphics, uses \pdfsetmatrix for rotating and scaling. Thus as workaround \scalebox and \rotatebox can be used for transformations (see cbe's comment to percusse's answer).

-
Can you give a link to your real hopgf package (instead of its documentation)? – Paul Gaborit Dec 16 '12 at 8:22
@PaulGaborit See section Installation how to get the package. – Heiko Oberdiek Dec 16 '12 at 10:12
I realize that I have many scaled tikzpicture with hyperref inside, spanned across several documents, so I'm going to use your patch (as soon as it will be available) to definitively fix the issue. In the meanwhile, percusse's answer is a very useful workaround. – cbe Dec 16 '12 at 14:00
@HeikoOberdiek hopgf.dtx is not on cpan and hopgf.sty is not in oberdiek.tds.zip... – Paul Gaborit Dec 16 '12 at 16:18
@PaulGaborit Yes, as I said it is not yet on CTAN (2012-12-16). You can either follow the instructions in the PDF file in subsection "4.5 Details for the interested" or wait until the next bundle update (perhaps next week). – Heiko Oberdiek Dec 16 '12 at 16:21