How to center a tikzpicture but still add an arrow to it

beamertikz-pgf

I have this MWE:

\documentclass[11pt]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc, matrix, overlay-beamer-styles, positioning}
\newcommand\Circle[1]{%
    \tikz[baseline=(char.base)]\node[circle,draw,inner sep=2pt] (char) {#1};}

\tikzset{circled/.style={path picture={
            \draw let \p1=($(path picture bounding box.north east)-(path picture bounding
            box.south west)$),\n1={min(\x1,\y1)/2.2} in
            (path picture bounding box.center) circle[radius=\n1];}},
    circled on/.style={alt=#1{circled}{}}}


\begin{document}

\begin{frame}[fragile,t]
    \frametitle{
        \only<1-2>{Title?}
    }
\begin{center}
    \begin{tikzpicture}
    \matrix (m) [matrix of nodes,
    nodes={draw, minimum size=8mm},
    column sep=3mm,
    row sep=2mm,
    row 7/.style={visible on=<2>},
    row 1/.style={nodes={draw=none}}] (mat)
    {
        0 & 1 & 2 & 3 & 4   \\[-3mm]
        6 & 2 & 4 & 4 & 5   \\
        |[circled on=<2>]| 8 & 4 &  |[circled on=<{2}>]| 5 & 6 &  |[circled on=<2>]| 6   \\
        7 & 5 & 2 & 7 & 5   \\
        6 & 5 & 1 & 6 & 5   \\
        5 & |[circled on=<2>]| 9 & 0 & 2 & 4   \\
        8 & 9 & 5 & 7 & 6   \\
    };
    \path (mat-6-1.south) -- (mat-7-1.north) coordinate[midway](aux);
    \draw[visible on=<2>] (mat.west|-aux) -- (mat.east|-aux);
    \node[right=1.5cm of mat-7-5.east, visible on=<2>] (label) {Column maxima};
    \draw[->, thick, visible on=<2>] (label.west) -- ++(-1, 0);
    \end{tikzpicture}
\end{center}

\end{frame}

\end{document}

In the second transition this gives me:

enter image description here

I want the matrix of numbers to be centred and the arrow+text to be to its right.

Best Answer

You can use the overlay option for all elements of the tikzpicture which should not take space:

\documentclass[11pt]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc, matrix, overlay-beamer-styles, positioning}
\tikzset{circled/.style={path picture={
            \draw let \p1=($(path picture bounding box.north east)-(path picture bounding
            box.south west)$),\n1={min(\x1,\y1)/2.2} in
            (path picture bounding box.center) circle[radius=\n1];}},
    circled on/.style={alt=#1{circled}{}}}

\begin{document}

\begin{frame}[fragile,t]
\frametitle{Title?}
\begin{center}
    \begin{tikzpicture}
    \matrix (m) [matrix of nodes,
    nodes={draw, minimum size=8mm},
    column sep=3mm,
    row sep=2mm,
    row 7/.style={visible on=<2>},
    row 1/.style={nodes={draw=none}}] (mat)
    {
        0 & 1 & 2 & 3 & 4   \\[-3mm]
        6 & 2 & 4 & 4 & 5   \\
        |[circled on=<2>]| 8 & 4 &  |[circled on=<{2}>]| 5 & 6 &  |[circled on=<2>]| 6   \\
        7 & 5 & 2 & 7 & 5   \\
        6 & 5 & 1 & 6 & 5   \\
        5 & |[circled on=<2>]| 9 & 0 & 2 & 4   \\
        8 & 9 & 5 & 7 & 6   \\
    };
    \path (mat-6-1.south) -- (mat-7-1.north) coordinate[midway](aux);
    \draw[visible on=<2>] (mat.west|-aux) -- (mat.east|-aux);   
    \node[overlay,right=1.5cm of mat-7-5.east, visible on=<2>,align=left] (label) {Column\\ maxima};
    \draw[overlay,->, thick, visible on=<2>] (label.west) -- ++(-1, 0);
    \end{tikzpicture}
\end{center}

\end{frame}

\end{document}

enter image description here