# TikZ, Beamer and matrix node iterative highlight ending in unwanted displacement

I have this code, and I want the blue-circled node to not expand the whole table when highlighted. With the additional minimum size option, the table stay unchanged, but the node moves, which is quite ugly :

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{frame}[fragile]
\begin{tikzpicture}
\footnotesize
\matrix (m) [matrix of nodes, row sep=1\pgflinewidth, column sep=1\pgflinewidth,
nodes={rectangle, draw=gray, minimum height=2em,
anchor=center, align=center,
inner sep=0pt, outer sep=0pt}]{
1 & 5 & 6 & 6 & 6 & 7 & 7 & 7 & 8 & 8 & 9 & 10 \\
\alt<2->{11 & 11 & 11 & 12 & 12 & 12 & 12 & 13 & 13 & 13 & 14 & |[draw, circle, blue, text width=1.5em]| 14}
{11 & 11 & 11 & 12 & 12 & 12 & 12 & 13 & 13 & 13 & 14 & 14 }\\
14 & 14 & 15 & 16 & 17 & 17 & 17 & 18 & 18 & 18 & 18 & 19 \\
19 & 20 & 20 & 20 & 23 & 26 & 29 & 29 & 31 & 32 & 32 & 34\\
} ;
\end{tikzpicture}
\end{frame}
\end{document}


Moreover, if someone knows a more elegant way to blend Beamer and TikZ matrix for changing nodes aspect, he's welcome! Thanks.

• Welcome to TeX.SX! I fixed your code up a little bit, to make it easier for people to help. In the future, if you can try and provide a complete and minimal document that reproduces your problem, including the \documentclass{...}, the minimal set of \usepackage{...} that are necessary, and the \begin{document}...\end{document} it would be very helpful. Thank you! For more information, please see here: minimal working example (MWE) – darthbith Oct 28 '15 at 12:06

Here's one way to do it. Notice also that using this approach, the code simplifies (I added a minimum width value just for the example, but you can remove it if you don't want to use it):

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}

\tikzset{onslide/.code args={<#1>#2}{%
\only<#1>{\pgfkeysalso{#2}}%
}
}

\begin{document}

\begin{frame}[fragile]
\begin{tikzpicture}
\footnotesize
\matrix (m) [
matrix of nodes,
row sep=1\pgflinewidth,
column sep=1\pgflinewidth,
nodes={
rectangle,
draw=gray,
minimum height=2em,
anchor=center,
align=center,
minimum width=2em,
inner sep=0pt,
outer sep=0pt
}
]
{
1 & 5 & 6 & 6 & 6 & 7 & 7 & 7 & 8 & 8 & 9 & 10 \\
11 & 11 & 11 & 12 & 12 & 12 & 12 & 13 & 13 & 13 & 14 & |[onslide=<2->{circle,overlay,blue}]|14 \\
14 & 14 & 15 & 16 & 17 & 17 & 17 & 18 & 18 & 18 & 18 & 19 \\
19 & 20 & 20 & 20 & 23 & 26 & 29 & 29 & 31 & 32 & 32 & 34\\
};
\end{tikzpicture}
\end{frame}

\end{document}


An animation of the result: