3

I have a diagram as an image. There are described different components which are later described and marked with \label tags.

Can I ref link different areas/sections of one image to different \label tags? Or do I have to combine the diagram out of different images and ref them each?

I am using the package hyperref at the moment.

\documentclass[11pt, a4paper, oneside]{article}

\usepackage{graphicx}
\usepackage{hyperref}

\begin{document}

\includegraphics[scale=0.2]{diagrammPicture.pdf}
% something like    \refInsidePicture{area1}{fromX}{toX}{fromY}{toY}
%                   \refInsidePicture{area2}{fromX}{toX}{fromY}{toY}
%                   \refInsidePicture{area3}{fromX}{toX}{fromY}{toY}
%                   \refInsidePicture{area4}{fromX}{toX}{fromY}{toY}
\section{area1 explained} \label{area1}
\section{area2 explained} \label{area2}
\section{area3 explained} \label{area3}
\section{area4 explained} \label{area4}
\end{document}
jub0bs
  • 58,916
  • Yes you can. Can you provide us with a minimal working example (MWE) that shows the community exactly what you mean? – Werner Jul 29 '14 at 06:00
  • If all you want is to link, use \hyperlink and \hypertarget. \label and \ref are intended to keep track of counters. – John Kormylo Jul 30 '14 at 12:50
  • @John Kormylo Thank you. I looked into the \hyperlink and \hypertarget docs and I do think that it is not what I searched. I do want something like the tag from HTML. HTML area: [http://stackoverflow.com/questions/18560097/how-to-make-a-section-of-an-image-a-clickable-link] – pizza_exclamationMark Jul 31 '14 at 08:40
  • Consider \hypertarget{area1}{\makebox[2in]{\rule{0pt}(1in}}. This will target an area 2 inches wide by 1 inch tall. Now all you need is to use \raisebox to overlay the areas onto the image. – John Kormylo Jul 31 '14 at 13:51

1 Answers1

2

It seems \hypertarget aims for the baseline, so I had to move the areas below the baseline.

\documentclass[11pt, a4paper, oneside]{article}

\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{mwe}

\newsavebox{\tempbox}
\newlength{\tempheight}
\newlength{\tempwidth}

\newcommand{\area}{\rule[-0.49\tempheight]{0.49\tempwidth}{0.49\tempheight}}
% better too small than too big

\begin{document}

\savebox{\tempbox}{\includegraphics[scale=0.5]{example-image}}
\settoheight{\tempheight}{\usebox{\tempbox}}
\settowidth{\tempwidth}{\usebox{\tempbox}}

\hfil\parbox{\tempwidth}{%
\hypertarget{area1}{\area}\hfill%
\hypertarget{area2}{\area}%
\newline%
\hypertarget{area3}{\area}\hfill%
\hypertarget{area4}{\area}%
\newline%
\raisebox{0pt}[0pt]{\usebox{\tempbox}}% overlay
}

\begin{center}
\hyperlink{area1}{upper left}
\hyperlink{area2}{upper right}
\hyperlink{area3}{lower left}
\hyperlink{area4}{lower right}
\end{center}

\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120