Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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}
share|improve this answer
    
Thanks so much! Just what I wanted! –  bencallis Jan 9 '13 at 21:34
    
How would I go about linking the big image back to the small one? That would be a nice bonus. –  bencallis Jan 9 '13 at 21:40
    
@bencallis you're welcome! see the update :) –  cmhughes Jan 9 '13 at 22:00
    
Great! One more thing I have previously used subfigure to position two figures side by side. Unfortunately using thumbnailandappendix in place of includegraphics does not seem to work there. "Something's wrong -- perhaps a missing \item" –  bencallis Jan 9 '13 at 23:29
    
@bencallis it works fine for me I have updated my answer with details –  cmhughes Jan 10 '13 at 0:42
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.