I have a series of slides/transitions showing one matrix where I insert some gaps between columns and circle numbers and at one point add an extra row at the bottom. I would like the matrix to stay in the same place vertically and for all the elements (which are boxed) to stay in the same place when all I do is circle a number or add a row at the bottom of the matrix (see example for what this means exactly). Basically, I would like it to stop jumping around as much as possible. How can I do this?
Here is a rather long example which shows the problem:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc, matrix}
\newcommand\Circle[1]{%
\tikz[baseline=(char.base)]\node[circle,draw,inner sep=2pt] (char) {#1};}
\begin{document}
\begin{frame}[fragile]
\frametitle{title}
\begin{center}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes={draw, minimum size=8mm},
column sep=3mm,
row sep=2mm,
row 1/.style={nodes={draw=none}}]
{
0 & 1 & 2 & 3 & 4 \\[-3mm]
6 & 2 & 4 & 4 & 5 \\
8 & 4 & 5 & 6 & 6 \\
7 & 5 & 2 & 7 & 5 \\
6 & 5 & 1 & 6 & 5 \\
5 & 9 & 0 & 2 & 4 \\
};
\end{tikzpicture}
\end{center}
\begin{itemize}
\item A line of text
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{title}
\begin{center}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes={draw, minimum size=8mm},
column sep=3mm,
row sep=2mm,
row 1/.style={nodes={draw=none}}]
{
0 & 1 & 2 & 3 & 4 \\[-3mm]
6 & 2 & 4 & 4 & 5 \\
\Circle{8} & 4 & \Circle{5} & 6 & \Circle{6} \\
7 & 5 & 2 & \Circle{7} & 5 \\
6 & 5 & 1 & 6 & 5 \\
5 & \Circle{9} & 0 & 2 & 4 \\
& & & & \\
\hline \\
8 & 9 & 5 & 7 & 6 \\
};
\end{tikzpicture}
\end{center}
\begin{itemize}
\item Some text
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{title}
\begin{center}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes={draw, minimum size=8mm},
column sep=3mm,
row sep=2mm,
row 1/.style={nodes={draw=none}}]
{
0 & 1 &[5mm] 2 &[5mm] 3 & 4 \\[-3mm]
6 & 2 & 4 & 4 & 5 \\
8 & 4 & \Circle{5} & 6 & 6 \\
7 & 5 & 2 & 7 & 5 \\
6 & 5 & 1 & 6 & 5 \\
5 & 9 & 0 & 2 & 4 \\
& & & & \\
\hline \\
8 & 9 & 5 & 7 & 6 \\
};
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{title}
\begin{center}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes={draw, minimum size=8mm},
column sep=3mm,
row sep=2mm,
row 1/.style={nodes={draw=none}}]
{
0 & 1 &[5mm] 2 & 3 & 4 \\[-3mm]
6 & 2 & 4 & 4 & 5 \\
8 & 4 & 5 & 6 & 6 \\
7 & 5 & 2 & 7 & 5 \\
6 & 5 & 1 & 6 & 5 \\
5 & 9 & 0 & 2 & 4 \\
& & & & \\
\hline \\
8 & 9 & 5 & 7 & 6 \\
};
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{title}
\begin{center}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes={draw, minimum size=8mm},
column sep=3mm,
row sep=2mm,
row 1/.style={nodes={draw=none}}]
{
0 & 1 & 2 &[5mm] 3 &[5mm] 4 \\[-3mm]
6 & 2 & 4 & 4 & 5 \\
8 & 4 & 5 & 6 & 6 \\
7 & 5 & 2 & 7 & 5 \\
6 & 5 & 1 & 6 & 5 \\
5 & 9 & 0 & 2 & 4 \\
& & & & \\
\hline \\
8 & 9 & 5 & 7 & 6 \\
};
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{title}
\begin{overlayarea}{\linewidth}{\textheight}
\begin{center}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
nodes={draw, minimum size=8mm},
column sep=3mm,
row sep=2mm,
row 1/.style={nodes={draw=none}}]
{
0 & 1 & 2 &[5mm] 3 &[5mm] 4 \\[-3mm]
6 & 2 & 4 & 4 & 5 \\
8 & 4 & 5 & 6 & 6 \\
7 & 5 & 2 & \Circle{7} & 5 \\
6 & 5 & 1 & 6 & 5 \\
5 & 9 & 0 & 2 & 4 \\
& & & & \\
\hline \\
8 & 9 & 5 & 7 & 6 \\
};
\end{tikzpicture}
\end{center}
\pause
\begin{itemize}
\item More text
\end{itemize}
\end{overlayarea}
\end{frame}
\end{document}

tikzpictures. This is to be avoided. I compiled your code and see what it does, but fail to understand what you mean by "I move columns of a matrix from left to right". As far as I can see the matrix gets largely preserved but only some gaps and circles appear. Could you please explain what you mean by that statement? – Feb 01 '20 at 18:28