3

I have been trying to add thumbnails as a column entry in {longtabu}.

LaTeX - Insert thumbnail with link to fullsize image contained in appendix came to the rescue.

Now, the thumbnails inserted as per the instructions in the above answer work perfectly, but the issue is that when I use the same thumbnail as a table entry, multiple duplicate images corresponding to that thumbnail get inserted in the appendix.

Would like to know a way to resolve this duplication.

Edit: MWE as asked for is here. I hope this serves the need.

\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{longtable, tabu}

% 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}
% 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}}}
} 

\begin{document}    
%works fins when used normally like this:
%\thumbnailandappendix{image.jpg}

%use of thumbnail in longtable that is leading to duplicate entries in appendix
\clearpage
\section{Images}
\begin{center}
    \begin{longtabu}{ | X[-1, l] |X[-1, l] |}

        \caption{Images Table}\\ \hline
        \hspace{0pt}FILENAME & \hspace{0pt}IMAGE REFERENCE \\ \hline \hline    \endhead

        image.jpg & \thumbnailandappendix{image.jpg}\\ \hline
    \end{longtabu}
\end{center}

\clearpage
\appendix

\section{Full-size image}

\unvbox\savedimgs

\end{document} 
}

Thanks.

P.S. I am a new member of this site and so do not have enough reputation points to directly comment on the link above and ask; and thereby I am asking this as a fresh question. Pardon me for deflecting from any rules, incase I did.

elixir
  • 133
  • 1
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Apr 08 '15 at 12:53
  • The only part of a longtable that I could imagine leading to duplicate images is the head and foot which are repeated on each page, so don't put the links in there, otherwise as Christian says, you need to show an example – David Carlisle Apr 08 '15 at 15:12
  • I have added the MWE as needed. Let know if it still needs any updates. You may change the image path in the code to an image in your local directory and then execute the code to see the issue I am referring to.

    Thanks

    – elixir Apr 09 '15 at 11:20
  • @DavidCarlisle Could you now see through the issue and help? – elixir Apr 16 '15 at 12:29
  • oh it's not longtable at all it's tabu, that is why you are getting multiple references, because the X columns require multiple trials to get the best width, you see that would have been impossible to tell from your original question. – David Carlisle Apr 16 '15 at 14:31
  • @DavidCarlisle Oh.. Thanks a lot for pointing this out. I realise the significance of MWE here now. Thanks again. – elixir Apr 17 '15 at 10:12

1 Answers1

3

The problem is unconnected to longtable the problem is that tabu X columns like the original tabularx X columns are set multiple times in trial runs to obtain the correct column widths.

To avoid writing labels and other things multiple times the code disables \write and some other commands while making trial runs, so you can detect that and not make a thumbnail until the final run.

\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{longtable, tabu}

% 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}
% 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}}}
} 

\let\realwrite\write
\begin{document}    
%works fins when used normally like this:
%\thumbnailandappendix{image.jpg}

%use of thumbnail in longtable that is leading to duplicate entries in appendix
\clearpage
\section{Images}
\begin{center}
    \begin{longtabu}{ | X[-1, l] |X[-1, l] |}

        \caption{Images Table}\\ \hline
        \hspace{0pt}FILENAME & \hspace{0pt}IMAGE REFERENCE \\ \hline \hline    \endhead

        image.jpg & \ifx\write\realwrite\thumbnailandappendix{example-image}\fi\\ \hline
    \end{longtabu}
\end{center}

\clearpage
\appendix

\section{Full-size image}

\unvbox\savedimgs

\end{document} 
David Carlisle
  • 757,742
  • Works perfectly. Thanks a ton. This issue had been pondering me for days. Apology for the misleading problem description. – elixir Apr 17 '15 at 10:31