2

With pdflatex the following

\documentclass{beamer}
\usepackage{hyperref}
\usepackage{tikz}
\begin{document}
  \begin{frame}
    \begin{figure}
        \hyperlink{bar}{
          \begin{tikzpicture}
                \filldraw (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
          \end{tikzpicture}
        }
        \hyperlink{bar}{
          \begin{tikzpicture}
                \filldraw (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
          \end{tikzpicture}
        }\\
        \begin{tikzpicture}
              \filldraw (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
        \end{tikzpicture}
        \begin{tikzpicture}
              \filldraw (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
        \end{tikzpicture}
  \end{figure}
 \end{frame}
\end{document}

yields a slide where spacing between the hyperlinked tikzpicture environments (upper row) is larger than the spacing between the non-hyperlinked tikzpicture environments (lower row). The same effect can also be seen when using e.g. \includegraphics. Is there a way to get rid of this spacing?

Laurent
  • 57

1 Answers1

4

A tikzpicture environment is basically like a letter/character box, so having no % after a \end{tikzpicture} will cause spacings as well as \hyperlink{bar}{ with the line break will add spurious spaces.

If any of those spacings should be 'killed', you have to place % after \hyperlink{bar}{ and after the links and after \end{tikzpicture} of the none-linked environments, as well as say \offinterlineskip -- the four images are contigious then.

See the differences between both methods.

\documentclass{beamer}
\usepackage{hyperref}
\usepackage{tikz}
\begin{document}
\begin{frame}
  \begin{figure}
    \hyperlink{bar}{%
      \begin{tikzpicture}
        \filldraw[blue] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
      \end{tikzpicture}%
    }
    \hyperlink{bar}{%
      \begin{tikzpicture}
        \filldraw[red] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
      \end{tikzpicture}%
    } 

    \begin{tikzpicture}
      \filldraw[yellow] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
    \end{tikzpicture}
    \begin{tikzpicture}
      \filldraw[green] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
    \end{tikzpicture}%
  \end{figure}

  \begin{figure}
    \hyperlink{bar}{%
      \begin{tikzpicture}
        \filldraw[blue] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
      \end{tikzpicture}%
    }%
    \hyperlink{bar}{%
      \begin{tikzpicture}
        \filldraw[red] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
      \end{tikzpicture}%
    }%
    \offinterlineskip% Only within groups!!!

    \begin{tikzpicture}
      \filldraw[yellow] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
    \end{tikzpicture}%
    \begin{tikzpicture}
      \filldraw[green] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
    \end{tikzpicture}%
  \end{figure}

\end{frame}
\end{document}

enter image description here