# tikz overlay changes width of resizebox

I have a beamer frame with a large matrix. I want to add some annotations to it, for which I use tikz overlays. However, the matrix (I suppose that it is the resizebox, actually) changes its width from frame to frame, which is highly undesired. Here is a minimum working example:

\documentclass{beamer}
\usepackage{tikz}

\begin{document}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node(#1) {};}

\frame
{
\resizebox{\textwidth}{!}
{
$\left(\begin{array}{rrrrrrrrrrrrrrrrrrrrrrrrrr}a & b & c & d & e & f & g & h & i & j & k & l & m & n & o & p & q & r & s & t & u & v & w & x & y & z\\ a & \tikzmark{b}b & c & d & e & f & g & h & i & j & k & l & m & n & o & p & q & r & s & t & u & v & w & x & y & z\end{array}\right)$
\only<1>
{
\begin{tikzpicture}[overlay,remember picture,-latex]
\draw[->] (b.east) -- +(1,-0.5) node[below] (btext) {This is b};
\end{tikzpicture}
}
}
\only<2>
{
\begin{tikzpicture}[overlay,remember picture,-latex]
\node[at=(btext)] {More text};
\end{tikzpicture}
}
}

\end{document}


The (undesired) effect looks like this:

I am using the overlay because I do not want the matrix to change its width from slide to slide. I am aware that my second text is outside of the resizebox - I want it to be overlayed with normal text size, i.e., so that it is unaffected by the resizebox.

What can I do to keep the width of the matrix unchanged between slides?

You have a lot of spurious spaces. When I remove them all, it works fine.

\documentclass{beamer}
\usepackage{tikz}

\begin{document}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node(#1) {};}

\frame
{%
\resizebox{\textwidth}{!}
{%
$\left(\begin{array}{rrrrrrrrrrrrrrrrrrrrrrrrrr}a & b & c & d & e & f & g & h & i & j & k & l & m & n & o & p & q & r & s & t & u & v & w & x & y & z\\ a & \tikzmark{b}b & c & d & e & f & g & h & i & j & k & l & m & n & o & p & q & r & s & t & u & v & w & x & y & z\end{array}\right)$%
\only<1>
{%
\begin{tikzpicture}[overlay,remember picture,-latex]
\draw[->] (b.east) -- +(1,-0.5) node[below] (btext) {This is b};
\end{tikzpicture}%
}%
}%
\only<2>
{%
\begin{tikzpicture}[overlay,remember picture,-latex]
\node[at=(btext)] {More text};
\end{tikzpicture}%
}%
}

\end{document}

• Thanks, that was it. I never quite understood why certain lines are o.k. without the % and why some are not. I'll certainly have to read up on that. May 5, 2016 at 14:10
• @AndreasUnterweger You can start with tex.stackexchange.com/questions/7453/… May 5, 2016 at 14:21