51

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

Martin Scharrer
  • 262,582
Maesumi
  • 9,059

4 Answers4

59

Just wrap the image in \href [1]

\documentclass{article}

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

\begin{document}
\href{http://www.google.de}{\includegraphics{image}}% [1]

\begin{figure}%[2]
    \centering
    \href{http://www.google.de}{\includegraphics{image}}
    \caption{Non linked caption.}
\end{figure}

%\begin{figure}%[3]
%   \centering
%   \href{http://www.google.de}{%
%       \includegraphics{image}
%       \caption{Linked captions won’t work.}
%   }
%\end{figure}

\begin{figure}%[4]
    \centering
    \href{http://www.google.de}{\includegraphics{image}}
    \caption{\href{http://www.google.de}{Workaround for linked captions}}
\end{figure}

\begin{figure}%[5]
    \href{http://www.google.de}{%
        \parbox{\textwidth}{
            \centering
            \includegraphics{image}
            \caption{Linked captions won’t work.}
        }
    }
\end{figure}

\begin{figure}%[6]
    \centering
    \href{http://www.google.de}{%
        \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.

David Carlisle
  • 757,742
Tobi
  • 56,353
  • 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 08 '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 08 '12 at 13:45
20

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}
Gonzalo Medina
  • 505,128
  • 1
    I use \href{https://gitlab.com/u/SomeName}{\includegraphics[width=0.31cm,height=0.31cm,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 '15 at 19:50
  • 1
    I found "my" answer here: http://tex.stackexchange.com/a/85103/8272 – Nikos Alexandris Oct 10 '15 at 20:12
13

Sure.

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

\href{http://www.dante.de}{\includegraphics[width=5cm]{tiger}}
\end{document}
Ulrike Fischer
  • 327,261
  • 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 08 '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 08 '12 at 13:40
  • 1
    @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 08 '12 at 13:41
  • @Maesumi: I added some possible ways to my answer whowing how to add a caption an link it. – Tobi May 08 '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 08 '12 at 19:37
0

I used a single command with orcid logo picture downloaded from google:

\href{https://orcid.org/0000-0001-9743-2851
}{\includegraphics[width=0.15in,height=0.15in]{orcid.jpg}}

Following is the picture I used

enter image description here