# How to insert an image that also acts as a link

Can an image be included in TeX so that the resulting PDF is clickable leading to a reference?

-

Just wrap the image in \href [1]

\documentclass{article}

\usepackage{hyperref}
\usepackage[demo]{graphicx}

\begin{document}

\begin{figure}%[2]
\centering
\end{figure}

%\begin{figure}%[3]
%   \centering
%       \includegraphics{image}
%   }
%\end{figure}

\begin{figure}%[4]
\centering
\end{figure}

\begin{figure}%[5]
\parbox{\textwidth}{
\centering
\includegraphics{image}
}
}
\end{figure}

\begin{figure}%[6]
\centering
\scalebox{0.5}{
\parbox{\textwidth}{
\centering
\textbf{A Title}\\
\includegraphics{image}}
}
}
\end{figure}

\end{document}


To add a caption just use the {figure} environment as usual and put in the linked graphic [2]: Wrapping the caption in \href too causes an error, since the out will contain paragraphs that can’t be part of a link [3], so you’ll have to link the caption too [4] or you must put the whole {figure} content in a \parbox, which can be linked [5]. [6] shows hoe to add a title (not caption) and scale text an image with \scalebox.

-
Nice update, but I have the feeling the OP talks about some sub-title below the image, not a real \caption. But I could be wrong of course. – Martin Scharrer May 8 '12 at 13:44
@MartinScharrer: We all can only guess what the OP want’s, but likely you’re right :-) I added this a possible code for this … – Tobi May 8 '12 at 13:45

Of course:

\documentclass{article}
\usepackage[demo]{graphicx}% demo option just for the example
\usepackage{hyperref}

\begin{document}

\href{http://www.tex.stackexchange.com}{\includegraphics{name}}

\end{document}

-
I use \href{https://gitlab.com/u/SomeName}{\includegraphics[width=0.31cm,height=0.31c‌​m,keepaspectratio]{figures/gitlab_greyscale}}, but it does not work. Compiling a memoir based document with XeLaTeX. Are there any restrictions (wrt XeLaTeX)? – Nikos Alexandris Oct 10 at 19:50
I found "my" answer here: tex.stackexchange.com/a/85103/8272 – Nikos Alexandris Oct 10 at 20:12

Sure.

\documentclass{article}
\usepackage{hyperref,graphicx}
\begin{document}

\href{http://www.dante.de}{\includegraphics[width=5cm]{tiger}}
\end{document}

-
Does the syntax allow for a title or caption, and would it scale with the picture? How would you give the coordinates for the picture? – Maesumi May 8 '12 at 13:23
You shouldn't put a float like figure in the argument. But I don't see any reason why boxes like \parbox or tabular with various content shouldn't work. If you want to scale a text, use \resizebox from the graphics package. – Ulrike Fischer May 8 '12 at 13:40
@Maesumi: You should always state such requirements with your question. Are you talking about a normal LaTeX figure numbered caption or just some text above or below? – Martin Scharrer May 8 '12 at 13:41
@Maesumi: I added some possible ways to my answer whowing how to add a caption an link it. – Tobi May 8 '12 at 13:43
With thanks to Tobi, Gonzola, Ulrike, Martin. I want a regular picture (not LaTeX generated) with some text that will be either above or below it. It does not have to be a formal caption or title for the picture, just so long as it centers with the picture. – Maesumi May 8 '12 at 19:37