Beamer:使用 tikzpicture 进行列对齐

Beamer:使用 tikzpicture 进行列对齐

我在使用 Beamer 类中的列时遇到了麻烦。出于某种原因,我必须在左列中显示一个图,然后用另一个图替换它以在其上显示其他数据(我无法在图中叠加,因为 pgfplots 不支持叠加单个坐标,无论如何...)。

为此,我必须使用\only<>命令显示一张图片,然后再显示另一张图片。我目前的问题是,即使在套印环境中,我也无法保持不同幻灯片之间右列(始终包含相同元素)的对齐。

这是 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}

这个 MWE 显示第 2 列在第 2 张和第 3 张幻灯片之间有一点垂直偏移。我不明白:因为我在套印环境中,所以列对齐应该用封闭的最高对象(即蓝色圆圈)来完成,但它不起作用。

我尝试改变列对齐参数(t,,,等等)并尝试了“overlayarea” Tc但它也没有用。

我希望你可以帮助我。

答案1

对于这类问题,最好还是依靠 Daniel 的方法思维导图 tikzpicture 在 beamer 中 (逐步显示).这有助于避免所谓的跳跃效应并且它非常容易使用:你只需要在代码中指定路径何时可见的选项:visible on=<...>

MWE 修订如下:

\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}

结果:

在此处输入图片描述


评论后解决正确的问题..

方法与以前相同:能见度条件现在应该应用于\addplot

代码:

\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}

结果:

在此处输入图片描述

相关内容