3

Consider image sample below. I'm including it using \includegraphics and I have linked it to an url using \href.

What I would like is to have it in the pdf file in such a way that the mouse would only allow you to follow the link when passing over the grey zone and not through the white background.

I'm using a png file with no background but with no success...

Does someone know how to do this?

Thank you so much in advance!

enter image description here:

  • 1
    The only way I can see this being possible is if you break up the shaded area into small rectangles (yes, a rectilinear object), overlap them with the shaded area manually and hyperlink them all. Good luck. – Werner May 9 '14 at 15:55
  • Hi Werner! Thanks for the answer. It would take me forever to get it done... So i'm going to give up on this feature. Although I would really love to have it :) Thanks anyway. – Pedro May 13 '14 at 17:23
  • This could be done, but it would take a lot of work. Basically one could construct a somewhat pixelated version of the image using a tikz matrix. For a 50x50 grid using 1 letter (local) macro names would involve 50 lines of 151 characters each. You would need both upper and lower case for the map shown. – John Kormylo Aug 12 '15 at 13:02
3

This was done on a smaller scale for a map of Hawaii using a 20x20 grid. For the final version you set the opacity of the map to 1. I find using a checkerboard background helps when aligning links to the map. Using a \parbox instead of tikz \matrix is much faster.

I stole the map from http://www.enchantedlearning.com/usa/states/hawaii/map.GIF and converted to png.

map of hawaii

\documentclass[multi={tikzpicture,minipage}]{standalone}
\usepackage{tikz}
\usepackage[hidelinks]{hyperref}

\newsavebox{\tempbox}
\newlength{\cellwidth}
\newlength{\cellheight}

\begin{document}
\savebox{\tempbox}{\includegraphics{images/map.png}}
\setlength{\cellwidth}{\dimexpr \wd\tempbox / 20}
\setlength{\cellheight}{\dimexpr \ht\tempbox / 20}
\begin{tikzpicture}
\def\a{\mbox{\color{white}\rule{\cellwidth}{\cellheight}}}
\def\b{\rule{\cellwidth}{\cellheight}}
\def\c{\hyperlink{kauai}{\color{red}\rule{\cellwidth}{\cellheight}}}
\def\d{\hyperlink{niihau}{\color{blue}\rule{\cellwidth}{\cellheight}}}
\def\e{\hyperlink{oahu}{\color{red}\rule{\cellwidth}{\cellheight}}}
\def\f{\hyperlink{molokai}{\color{red}\rule{\cellwidth}{\cellheight}}}
\def\g{\hyperlink{lanai}{\color{red}\rule{\cellwidth}{\cellheight}}}
\def\h{\hyperlink{maui}{\color{blue}\rule{\cellwidth}{\cellheight}}}
\def\i{\hyperlink{kahoolawe}{\color{green}\rule{\cellwidth}{\cellheight}}}
\def\j{\hyperlink{hawaii}{\color{red}\rule{\cellwidth}{\cellheight}}}
\node (links) {\parbox{\wd\tempbox}{\lineskip=0pt
\a\b\a\c\c\b\a\b\a\b\a\b\a\b\a\b\a\b\a\b\\
\b\d\c\c\c\a\b\a\b\a\b\a\b\a\b\a\b\a\b\a\\
\a\d\a\c\a\b\a\b\a\b\a\b\a\b\a\b\a\b\a\b\\
\b\a\b\a\b\a\b\a\e\a\b\a\b\a\b\a\b\a\b\a\\
\a\b\a\b\a\b\a\b\e\b\a\b\a\b\a\b\a\b\a\b\\
\b\a\b\a\b\a\b\a\e\e\b\a\b\a\b\a\b\a\b\a\\
\a\b\a\b\a\b\a\b\a\b\a\f\f\b\a\b\a\b\a\b\\
\b\a\b\a\b\a\b\a\b\a\b\a\b\h\b\a\b\a\b\a\\
\a\b\a\b\a\b\a\b\a\b\a\g\g\h\h\b\a\b\a\b\\
\b\a\b\a\b\a\b\a\b\a\b\g\b\h\h\h\b\a\b\a\\
\a\b\a\b\a\b\a\b\a\b\a\b\i\i\a\b\a\b\a\b\\
\b\a\b\a\b\a\b\a\b\a\b\a\b\a\b\a\b\a\b\a\\
\a\b\a\b\a\b\a\b\a\b\a\b\a\b\a\j\j\b\a\b\\
\b\a\b\a\b\a\b\a\b\a\b\a\b\a\b\j\j\j\b\a\\
\a\b\a\b\a\b\a\b\a\b\a\b\a\b\a\j\j\j\j\b\\
\b\a\b\a\b\a\b\a\b\a\b\a\b\a\b\j\j\j\j\a\\
\a\b\a\b\a\b\a\b\a\b\a\b\a\b\a\j\j\j\j\b\\
\b\a\b\a\b\a\b\a\b\a\b\a\b\a\b\j\j\j\j\a\\
\a\b\a\b\a\b\a\b\a\b\a\b\a\b\a\j\j\b\a\b\\
\b\a\b\a\b\a\b\a\b\a\b\a\b\a\b\j\j\a\b\a}};
\node[opacity=.5] at (links) {\usebox{\tempbox}};
\end{tikzpicture}
\begin{minipage}{2cm}\hypertarget{niihau}{Niihau}\end{minipage}
\begin{minipage}{2cm}\hypertarget{kauai}{Kauai}\end{minipage}
\begin{minipage}{2cm}\hypertarget{oahu}{Oahu}\end{minipage}
\begin{minipage}{2cm}\hypertarget{molokai}{Molokai}\end{minipage}
\begin{minipage}{2cm}\hypertarget{lanai}{Lanai}\end{minipage}
\begin{minipage}{2cm}\hypertarget{maui}{Maui}\end{minipage}
\begin{minipage}{2cm}\hypertarget{kahoolawe}{Kahoolawe}\end{minipage}
\begin{minipage}{2cm}\hypertarget{hawaii}{Hawaii}\end{minipage}
\end{document}

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.