[Tex/LaTex] LaTeX – Insert thumbnail with link to fullsize image contained in appendix

cross-referencinggraphicslinks

What is the best way to include a small thumbnail image which links to the fullsize image which should be contained in the appendix?

Ideally it would be nice to have a macro which created a thumbnail inline and also automatically added a larger image to the appendices. Does this exist?

— Edit —

Issue with subfigure.

\begin{figure}[H]
    \begin{subfigure}
        \centering
    \thumbnailandappendix{images/iPadMyPdfs} 
    \end{subfigure}%
    \begin{subfigure}
        \centering
    \thumbnailandappendix{images/iPadMyPdfsPort} 
    \end{subfigure}
\caption{Main Tab}
\end{figure}

Output

Packages used

\usepackage{array} %% so can bold columns in a latex table
\usepackage{float} %% used to help position images exactly where typed
\usepackage{subfigure}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{hyperref}

Best Answer

Here's a solution that uses the hyperref package's commands

\hyperlink{<name of link>}{<text or image>}

and

 \hypertarget{<name of link>}{<text or image>}

It defines the command \thumbnailandappendix which takes one argument- the name of the image. This command

  • outputs the thumbnail to the page
  • saves a bigger version of the thumbnail in a vbox to be used later in the appendix
  • uses a counter thumbnail to keep the hyperlinks unique

The clever bit comes from David Carlisle's answer to Write content of box to a file

\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
%\usepackage[left]{showlabels}
%\showlabels{hypertarget}
%\showlabels{hyperlink}

% set up a counter for links
\newcounter{thumbnail}

% to store the images for later
\newbox\savedimgs
\setbox\savedimgs\vbox{}

% thumbnail and appendix command
\newcommand{\thumbnailandappendix}[1]{%
  % #1: name of image
  \refstepcounter{thumbnail}
  % input thumbnail version
  \hyperlink{big\thethumbnail}{\includegraphics[width=1cm,height=1cm]{#1}}
  % save the big version for later
  \global\setbox\savedimgs\vbox{%
  \unvbox\savedimgs
  \bigskip
  \filbreak
  \noindent
  \hypertarget{big\thethumbnail}{}

  \includegraphics[width=10cm,height=10cm]{#1}}
  }


\begin{document}

\thumbnailandappendix{Tux}

\thumbnailandappendix{babbytux}

\clearpage

\appendix

\section{Full-size image}

\unvbox\savedimgs

\end{document}

The showlabels package is especially useful during debugging.

The solution can be made to link the 'big' images back the thumbnails, however, this only makes sense if the thumbnail is used once

% thumbnail and appendix command
\newcommand{\thumbnailandappendix}[1]{%
  % #1: name of image
  \refstepcounter{thumbnail}
  % set up hypertarget before the thumbnail
  \hypertarget{small\thethumbnail}{}

  % input thumbnail version
  \hyperlink{big\thethumbnail}{\includegraphics[width=1cm,height=1cm]{#1}}
  % save the big version for later
  \global\setbox\savedimgs\vbox{%
  \unvbox\savedimgs
  \bigskip
  \filbreak
  \noindent
  \hypertarget{big\thethumbnail}{}

  \hyperlink{small\thethumbnail}{\includegraphics[width=10cm,height=10cm]{#1}}}
  }

If the thumbnail is used more than once, then the 'big' image will link back to the most recent thumbnail.

Note: the blank lines are intentional, and important in this macro.

You can use this command in the subfigure environment from the subcaption as expected; make sure to load subcaption before hyperref

\usepackage{subcaption}
\usepackage{hyperref}

and then you can use (for example)

\begin{figure}
    \begin{subfigure}{.5\textwidth}
        \centering
        \thumbnailandappendix{Tux}
        \caption{}
    \end{subfigure}%
    \begin{subfigure}{.5\textwidth}
        \centering
        \thumbnailandappendix{Tux}
        \caption{}
    \end{subfigure}
\end{figure}
Related Question