[Tex/LaTex] Beamer: column alignment with tikzpicture inside

beamercolumnstikz-pgfvertical alignment

I am having trouble with using columns in Beamer class. For some reason, I have to display a plot in the left column, then replacing it with another plot to display additional data on it (I can not overlay within the plot itself since pgfplots does not support overlaying single coordinates, whatever…).

For this I have to use the \only<> command to display a picture, then another. My current issue is that I am not able to keep alignment of right column (which contains always the same elements) between different slides even within an overprint environment.

Here is a MWE

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[frenchb]{babel}
\usepackage{tikz}
\usetheme{Frankfurt}

\begin{document}

\begin{frame}\frametitle{test}
\begin{columns}[onlywidth,T]
    \begin{column}{.7\textwidth}
        \begin{overprint}
        \centering
        column 1\\
        \only<2>{\tikz \draw (0,0) circle (.5cm);}
        \only<3->{\tikz \draw[blue] (0,0) circle (2cm);}
        \end{overprint}
    \end{column}

    \begin{column}{.3\textwidth}
        \begin{overprint}
        \centering
        column 2\\
        {\tikz \draw (0,0) circle (1cm);}
        \end{overprint}
    \end{column}


\end{columns}
\end{frame}



\end{document}

This MWE shows that column 2 has a little vertical shifts between slides 2 and 3. I don't get it : since I am in an overprint environment, column alignments should be done with the highest object enclosed, i.e. the blue circle, but it does not work.

I tried do change column alignment argument (t, T, c, etc.) and tried "overlayarea" but it didn't work either.

I hope you can help me.

Best Answer

For this kind of problems it is always better to rely to Daniel's method shown in Mindmap tikzpicture in beamer (reveal step by step). It helps to avoid the so called jumping effect and it is very easy to be used: you just have to specify as option when a path should be visible; in code: visible on=<...>.

The MWE revised:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[frenchb]{babel}
\usepackage{lmodern} % to avoid the warning about font size substitution 
\usepackage{tikz}
\usetheme{Frankfurt}

\tikzset{
    invisible/.style={opacity=0,text opacity=0}, % added text opacity to fix problems when nodes' text is opaque
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
  }

\begin{document}

\begin{frame}\frametitle{test}
\begin{columns}[onlywidth,T]
    \begin{column}{.7\textwidth}
       \centering
       column 1\\[1ex]
       \tikz \draw[visible on=<2>] (0,0) circle (.5cm);
       \tikz \draw[blue,visible on=<3->] (0,0) circle (2cm);
    \end{column}

    \begin{column}{.3\textwidth}
        \centering
        column 2\\[1ex]
        \tikz \draw (0,0) circle (1cm);
    \end{column}
\end{columns}
\end{frame}
\end{document}

The result:

enter image description here


Solving the right problem after the comment..

The approach is identical as did before: the visibility condition should be applied now to the \addplot.

The code:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[frenchb]{babel}
\usepackage{lmodern} % to avoid the warning about font size substitution 
\usepackage{pgfplots}
\pgfplotsset{compat=1.7} % use just with an updated TeXLive distribution otherwise search for your current pgfplots version
\usetheme{Frankfurt}

\tikzset{
    invisible/.style={opacity=0,text opacity=0}, % added text opacity to fix problems when nodes' text is opaque
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
  }

\begin{document}

\begin{frame}\frametitle{test}
\begin{columns}
    \begin{column}{.49\textwidth}
        \centering
        \only<1>{The plot of $\exp x$}\only<2>{The plot of $\exp 3x$}\only<3>{The plot of $\exp 6x$}\\[1ex]
       \begin{tikzpicture}
        \begin{semilogyaxis}[width=\textwidth,font=\scriptsize]
        \addplot [domain=0:3,visible on=<1>]{exp(x)};
        \addplot [domain=0:3,visible on=<2>]{exp(3*x)};
        \addplot [domain=0:3,visible on=<3>]{exp(6*x)};
        \end{semilogyaxis}
        \end{tikzpicture}
    \end{column}

    \begin{column}{.49\textwidth}
        \centering
        \only<1,2,3>{The plot of $\sin x$}\\[1ex]
       \begin{tikzpicture}
        \begin{axis}[width=\textwidth,font=\scriptsize]
        \addplot[blue,domain=0:360,visible on=<{1,2,3}>] {sin(x)}
        [yshift=8pt]
        node[pos=0] {$0$}
        node[pos=0.25,below=0.25cm] {$\pi/2$}
        node[pos=0.5] {$\pi$}
        node[pos=0.75] {$3/2\pi$}
        node[pos=1] {$2\pi$}
        ;
        \end{axis}
        \end{tikzpicture}

    \end{column}
\end{columns}
\end{frame}
\end{document}

The result:

enter image description here