0

I'm trying to achieve something similar to an html image map, i.e. linking certain areas of an image to different labels in my document.

Problems I'm facing:

  • The picture is too big for the page and therefore scaled down. How can I ensure that the overlay scales the same?
  • I want the overlay itself to be invisible and fill an area. I was able to achieve this using TikZ nodes with an opaque image. Is there a better way, e.g. a TikZ command to make the entire node a reference and not only the contents of it?
  • the code will be generated automatically, so manually making the positions work is not an option. Any calculations made should work for every (or at least a wide range of) picture size/scale.

I looked at this post: Possibility to ref link different areas of an image to different labels? but I don't think I can achieve the desired accuracy and flexibility for the map coordinates using \rule.

I tried what is suggested here: Drawing on an image with TikZ using own coordinate system but have issues with the coordinate system of the overlay.

This is some sample code:

\documentclass[10pt,twoside,a4paper,openany]{report}
\usepackage{tikz}
\usepackage{pdflscape}
\usepackage[pdftex]{hyperref}

\newlength\iwidth
\newlength\iheight

\begin{document}
\begin{landscape}
\begin{figure}[h]\centering
\settoheight\iheight{\includegraphics[width=1.414\textheight, totalheight=\textheight, keepaspectratio]{fig_2}}
\settowidth\iwidth{\includegraphics[width=1.414\textheight, totalheight=\textheight, keepaspectratio]{fig_2}}
\begin{tikzpicture}[x=\iwidth/1320,y=\iheight/864]
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=1.414\textheight, totalheight=\textheight, keepaspectratio]{fig_2}};
    \node[anchor=south west,inner sep=0,minimum height = 5mm, minimum width = 5mm, opacity=0.1] (block1) at (50,100) {\hyperref[TEM_TExMnfldMdl/TEM_TExMnfldMdl/EfficiencyCalculation]{\includegraphics[width=20pt, height=10pt]{dummyPicture}}};

\end{tikzpicture}
\caption[TEM\_TExMnfldMdl]{TEM\_TExMnfldMdl}\label{fig_2}
\end{figure}
\end{landscape}
\newpage
\subsection[EfficiencyCalculation]{TEM\_TExMnfldMdl\_EfficiencyCalculation}   \label{TEM_TExMnfldMdl/TEM_TExMnfldMdl/EfficiencyCalculation}
\end{document}

Open issues with this are the need for a dummy picture and that i cannot manage to get the positions of the overlay calculated from the position of the box in the unscaled image.

Thanks for any help or hints regarding this!

  • Perhaps something like this: tex.stackexchange.com/questions/305747/… ? – user31729 Jan 3 '17 at 21:51
  • Welcome! Load hyperref last. Don't specify the driver when loading it. Don't load epstopdf at all. Use \usepackage{} in the preamble rather than \RequirePackage{}. – cfr Jan 3 '17 at 23:48
  • @ChristianHupfer: I had seen that post, but I'm not sure how to apply the variable sizes of the nodes in my case. When drawing a rectangle, it is not clickable. So I somehow need a node that is a rectangle of a specific size, where the entire rectangle is a link. – Jochen P Jan 4 '17 at 9:09
  • @cfr: Thanks, in my case the image is an .eps file, therefore I needed epstopdf. The \RequirePackagecomes from copy pasting it from a .sty file I was using to create this example. – Jochen P Jan 4 '17 at 9:14
  • Updated the code to reflect cfrs suggestions. – Jochen P Jan 4 '17 at 9:22
1

Ok, I think i figured most of it out regarding the positioning of the overlay:

\documentclass[10pt,twoside,a4paper,openany]{report}
\usepackage{tikz}
\usepackage{pdflscape}
\usepackage{etex}
\usepackage[pdftex]{hyperref}

\newlength\iwidth
\newlength\iheight

\begin{document}
\begin{landscape}
\begin{figure}[h]\centering
\settoheight\iheight{\includegraphics[width=1.414\textheight, totalheight=\textheight, keepaspectratio]{fig_2}}
\settowidth\iwidth{\includegraphics[width=1.414\textheight, totalheight=\textheight, keepaspectratio]{fig_2}}
\begin{tikzpicture}[x=\iwidth/1320,y=\iheight/864]
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=1.414\textheight, totalheight=\textheight, keepaspectratio]{fig_2}};
    \node[anchor=south west,inner sep=0,minimum height = 5mm, minimum width = 5mm, opacity=0] (block1) at (175,279) {\hyperref[TEM_TExMnfldMdl/TEM_TExMnfldMdl/EfficiencyCalculation]{\includegraphics[width=\dimexpr\iwidth*210/1320, height=\dimexpr\iheight*220/864]{dummyPicture}}};

\end{tikzpicture}
\caption[TEM\_TExMnfldMdl]{TEM\_TExMnfldMdl}\label{fig_2}
\end{figure}
\end{landscape}
\newpage
\subsection[EfficiencyCalculation]{TEM\_TExMnfldMdl\_EfficiencyCalculation}   \label{TEM_TExMnfldMdl/TEM_TExMnfldMdl/EfficiencyCalculation}
\end{document}

Where 1320 and 864 are the size of the unscaled picture, 175 and 279 are the lower left corner of the overlay and 210 and 220 are the size of the overlay for the unscaled picture.

Will still try to get around the dummy picture somehow and edit here if I can make it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.