最近我发现我可以创造蒂克兹演示文稿投影仪文件中的图形。以前我习惯单独创建 pdf 文件并将其导入到演示文稿中。通过应用新流程,我遇到了一个问题,我不知道如何解决它。
我想在一张幻灯片中使用两个单独的 tikz 图形,它们将使用 \visible<1-2>{} 效果一个接一个地出现。我以前通过导入图形或 pdf 文件成功做到了这一点,但现在我陷入了困境。
我不知道如何使所有图形的垂直和水平间距相同。
代码示例演示了我的问题。幻灯片 2 和幻灯片 3 之间的问题很容易发现。图形移动到了不同的位置。
我使用了 \vspace{} 并设法使它们更接近一些,但不是我想要的结果。
有人知道如何提高我的产出吗?
提前感谢您花时间和精力阅读和回答我的问题。
\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage[english]{babel}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric , arrows , positioning}
\mode<presentation>
\usetheme{Dresden} % so so
\setbeamertemplate{blocks}[rounded][shadow=true]
\setbeamertemplate{navigation symbols}{} %take out the navigation symbols
\captionsetup{labelformat=simple}
\usefonttheme[stillsansseriflarge]{structureitalicserif}
\expandafter\def\expandafter\insertshorttitle\expandafter{%
\insertshorttitle\hfill\insertframenumber\,/\,\inserttotalframenumber}%page numbering
\begin{document}
\begin{frame}{Frame Title}
\setbeamercovered{dynamic}%Makes the text appear before it presents nice!!!!
\begin{columns}[t] % contents are top vertically aligned
\begin{column}[T]{.5\textwidth} % each column can also be its own environment
\begin{itemize}
\item<+-| alert@+> \invisible<2-4>{Comment 1}
\item<+-| alert@+> \invisible<3-4>{Comment 2}
\item<+-| alert@+> \invisible<4-4>{Comment 3}
\item<+-| alert@+> My last comment.
\end{itemize}
\end{column}
\begin{column}[t]{.5\textwidth} % alternative top-align that's better for graphics
\begin{figure}
\visible<1-2>{%
\begin{subfigure}[b]{1.0\linewidth}
\vspace*{-1.cm}
\caption{Sub caption 1 \label{fig:captionSmallOne}}
\resizebox{\textwidth}{!}{%
\begin{tikzpicture}[xscale=1.0]
\draw [thick] (0.0, 2.0) -- (10, 2.0);
\node[align=center, above] at (0.9, 2.0)%
{Sample 1};
\draw [thick] (3.0, 2.0) -- (3.0, 3.1);
\node[align=center, above] at (3.0, 3.1)%
{Line 1};
\draw [thick] (6.0, 2.0) -- (6.0, 3.1);
\node[align=center, above] at (6.0, 3.1)%
{Line 2};
\draw [thick] (9.0, 2.0) -- (9.0, 3.1);
\node[align=center, above] at (9.0, 3.1)%
{Line 3};
\draw [fill=green] (3, 2.0) rectangle (6.0, 2.9);
\draw [fill=orange] (3, 0.0) rectangle (6.5, 0.9);
\draw [thick] (0.0, 0.0) -- (10, 0.0);
\node[align=center, above] at (0.9,0.0)%
{Sample 2};
\draw [thick] (3.0,.0) -- (3.0, 2.0);
\draw [thick] (3.5,-.3) -- (3.5,1.1);
\node[align=center, below] at (3.5,-0.3)%
{Line 4};
\draw [thick] (6.5,-.3) -- (6.5,1.1);
\node[align=center, below] at (6.5,-0.3)%
{Line 5};
\draw [thick] (9.5,-.3) -- (9.5,1.1);
\node[align=center, below] at (9.5,-0.3)%
{Line 6};
\draw [->,thick] (4.2, 4.2) -- (4.2, 3.7);
\node[align=center, above] at (4.2, 4.1)%
{Event 1};
\draw [thick, dashed] (6.0, 2.0) -- (6.5, 1.0);
\draw [thick, dashed] (4.2, 0.0) -- (4.2, 3.6);
\end{tikzpicture}
}%
%\end{adjustbox}
\end{subfigure} \hfill
} % End visible 1-2
\visible<3-4>{%%
\begin{subfigure}[b]{1.0\linewidth}
\vspace*{-3.0cm}
\caption{Sub caption 2 \label{fig:captionSmallTwo}}
\resizebox{\textwidth}{!}{%
\begin{tikzpicture}[xscale=1.0]
\draw [thick] (0.0, 2.0) -- (10, 2.0);
\node[align=center, above] at (0.9, 2.0)%
{TestS 1};
\draw [thick] (3.0, 2.0) -- (3.0, 3.1);
\node[align=center, above] at (3.0, 3.1)%
{Line 1};
\draw [thick] (6.0, 2.0) -- (6.0, 3.1);
\node[align=center, above] at (6.0, 3.1)%
{Line 2};
\draw [thick] (9.0, 2.0) -- (9.0, 3.1);
\node[align=center, above] at (9.0, 3.1)%
{Line 3};
\draw [fill=green] (3, 2.0) rectangle (6.0, 2.9);
\draw [fill=orange] (3, 0.0) rectangle (3.5, 0.9);
\draw [thick] (0.0, 0.0) -- (10, 0.0);
\node[align=center, above] at (0.9,0.0)%
{Sample 2};
\draw [thick] (3.0,.0) -- (3.0, 2.0);
\draw [thick] (3.5,-.3) -- (3.5,1.1);
\node[align=center, below] at (3.5,-0.3)%
{Line 4};
\draw [thick] (6.5,-.3) -- (6.5,1.1);
\node[align=center, below] at (6.5,-0.3)%
{Line 5};
\draw [thick] (9.5,-.3) -- (9.5,1.1);
\node[align=center, below] at (9.5,-0.3)%
{Line 6};
\draw [->,thick] (3.3, 4.2) -- (3.3, 3.7);
\node[align=center, above] at (3.2, 4.1)%
{Event 2};
\draw [thick, dashed] (6.0, 2.0) -- (3.5, 1.1);
\draw [thick, dashed] (3.3, 0.0) -- (3.3, 3.6);
\end{tikzpicture}
}%
%\end{adjustbox}
\end{subfigure} \hfill
} % End visible 3-4
\captionsetup{justification=centering} %Center a two line caption
\caption{The big caption} \protect\label{fig:big}
\end{figure}
\end{column}
\end{columns}
\end{frame}
\end{document}
答案1
更新
在这个更新版本中,我仍然使用\only
而不是\visible
,并使用visible on
样式来大大简化代码;使用这种新方法,图像不会“跳跃”,因为大部分图形保持不变(overlayarea
仍然可以使用,但我认为不再需要了)。计数器subfigure
必须手动更新:
\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage[english]{babel}
\usepackage[compatibility=false]{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric , arrows , positioning}
\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}
}
}
\mode<presentation>
\usetheme{Dresden} % so so
\setbeamertemplate{blocks}[rounded][shadow=true]
\setbeamertemplate{navigation symbols}{} %take out the navigation symbols
\captionsetup{labelformat=simple}
\usefonttheme[stillsansseriflarge]{structureitalicserif}
\expandafter\def\expandafter\insertshorttitle\expandafter{%
\insertshorttitle\hfill\insertframenumber\,/\,\inserttotalframenumber}%page numbering
\begin{document}
\begin{frame}{Frame Title}
\setbeamercovered{dynamic}%Makes the text appear before it presents nice!!!!
\begin{columns}[t] % contents are top vertically aligned
\begin{column}[T]{.5\textwidth} % each column can also be its own environment
\begin{itemize}
\item<+-| alert@+> \invisible<2-4>{Comment 1}
\item<+-| alert@+> \invisible<3-4>{Comment 2}
\item<+-| alert@+> \invisible<4-4>{Comment 3}
\item<+-| alert@+> My last comment.
\end{itemize}
\end{column}
\begin{column}[T]{.5\textwidth} % alternative top-align that's better for graphics
\begin{figure}
\begin{subfigure}{1.0\linewidth}
\only<1-2>{\caption{Sub caption 1 \label{fig:captionSmallOne}}}
\only<3-4>{\stepcounter{subfigure}\caption{Sub caption 2 \label{fig:captionSmallTwo}}}
\resizebox{\textwidth}{!}{%
\begin{tikzpicture}[xscale=1.0,baseline]
\draw [thick] (0.0, 2.0) -- (10, 2.0);
\node[align=center, above,visible on=<1-2>] at (0.9, 2.0)%
{Sample 1};
\node[align=center, above,visible on=<3-4>] at (0.9, 2.0)%
{TestS 1};
\draw [thick] (3.0, 2.0) -- (3.0, 3.1);
\node[align=center, above] at (3.0, 3.1)%
{Line 1};
\draw [thick] (6.0, 2.0) -- (6.0, 3.1);
\node[align=center, above] at (6.0, 3.1)%
{Line 2};
\draw [thick] (9.0, 2.0) -- (9.0, 3.1);
\node[align=center, above] at (9.0, 3.1)%
{Line 3};
\draw [fill=green] (3, 2.0) rectangle (6.0, 2.9);
\draw [fill=orange] (3, 0.0) rectangle (6.5, 0.9);
\draw [thick] (0.0, 0.0) -- (10, 0.0);
\node[align=center, above] at (0.9,0.0)%
{Sample 2};
\draw [thick] (3.0,.0) -- (3.0, 2.0);
\draw [thick] (3.5,-.3) -- (3.5,1.1);
\node[align=center, below] at (3.5,-0.3)%
{Line 4};
\draw [thick] (6.5,-.3) -- (6.5,1.1);
\node[align=center, below] at (6.5,-0.3)%
{Line 5};
\draw [thick] (9.5,-.3) -- (9.5,1.1);
\node[align=center, below] at (9.5,-0.3)%
{Line 6};
\draw [->,thick,visible on=<1-2>] (4.2, 4.2) -- (4.2, 3.7);
\draw [->,thick,visible on=<3-4>] (3.3, 4.2) -- (3.3, 3.7);
\node[align=center, above,visible on=<1-2>] at (4.2, 4.1)%
{Event 1};
\node[align=center, above,visible on=<3-4>] at (3.2, 4.1)%
{Event 2};
\draw [thick, dashed,visible on=<1-2>] (6.0, 2.0) -- (6.5, 1.0);
\draw [thick, dashed,visible on=<1-2>] (4.2, 0.0) -- (4.2, 3.6);
\draw [thick, dashed,visible on=<3-4>] (6.0, 2.0) -- (3.5, 1.1);
\draw [thick, dashed,visible on=<3-4>] (3.3, 0.0) -- (3.3, 3.6);
\end{tikzpicture}
}%
\end{subfigure} \hfill
\captionsetup{justification=centering} %Center a two line caption
\caption{The big caption} \protect\label{fig:big}
\end{figure}
\end{column}
\end{columns}
\end{frame}
\end{document}
第一个版本
您可以使用overlayarea
和\only
代替\visible
:
\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage[english]{babel}
\usepackage[compatibility=false]{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric , arrows , positioning}
\mode<presentation>
\usetheme{Dresden} % so so
\setbeamertemplate{blocks}[rounded][shadow=true]
\setbeamertemplate{navigation symbols}{} %take out the navigation symbols
\captionsetup{labelformat=simple}
\usefonttheme[stillsansseriflarge]{structureitalicserif}
\expandafter\def\expandafter\insertshorttitle\expandafter{%
\insertshorttitle\hfill\insertframenumber\,/\,\inserttotalframenumber}%page numbering
\begin{document}
\begin{frame}{Frame Title}
\setbeamercovered{dynamic}%Makes the text appear before it presents nice!!!!
\begin{columns}[t] % contents are top vertically aligned
\begin{overlayarea}{\textwidth}{\textheight}
\begin{column}[T]{.5\textwidth} % each column can also be its own environment
\begin{itemize}
\item<+-| alert@+> \invisible<2-4>{Comment 1}
\item<+-| alert@+> \invisible<3-4>{Comment 2}
\item<+-| alert@+> \invisible<4-4>{Comment 3}
\item<+-| alert@+> My last comment.
\end{itemize}
\end{column}
\begin{column}[t]{.5\textwidth} % alternative top-align that's better for graphics
\begin{figure}
\only<1-2>{%
\begin{subfigure}[t]{1.0\linewidth}
\caption{Sub caption 1 \label{fig:captionSmallOne}}
\resizebox{\textwidth}{!}{%
\begin{tikzpicture}[xscale=1.0]
\draw [thick] (0.0, 2.0) -- (10, 2.0);
\node[align=center, above] at (0.9, 2.0)%
{Sample 1};
\draw [thick] (3.0, 2.0) -- (3.0, 3.1);
\node[align=center, above] at (3.0, 3.1)%
{Line 1};
\draw [thick] (6.0, 2.0) -- (6.0, 3.1);
\node[align=center, above] at (6.0, 3.1)%
{Line 2};
\draw [thick] (9.0, 2.0) -- (9.0, 3.1);
\node[align=center, above] at (9.0, 3.1)%
{Line 3};
\draw [fill=green] (3, 2.0) rectangle (6.0, 2.9);
\draw [fill=orange] (3, 0.0) rectangle (6.5, 0.9);
\draw [thick] (0.0, 0.0) -- (10, 0.0);
\node[align=center, above] at (0.9,0.0)%
{Sample 2};
\draw [thick] (3.0,.0) -- (3.0, 2.0);
\draw [thick] (3.5,-.3) -- (3.5,1.1);
\node[align=center, below] at (3.5,-0.3)%
{Line 4};
\draw [thick] (6.5,-.3) -- (6.5,1.1);
\node[align=center, below] at (6.5,-0.3)%
{Line 5};
\draw [thick] (9.5,-.3) -- (9.5,1.1);
\node[align=center, below] at (9.5,-0.3)%
{Line 6};
\draw [->,thick] (4.2, 4.2) -- (4.2, 3.7);
\node[align=center, above] at (4.2, 4.1)%
{Event 1};
\draw [thick, dashed] (6.0, 2.0) -- (6.5, 1.0);
\draw [thick, dashed] (4.2, 0.0) -- (4.2, 3.6);
\end{tikzpicture}
}%
%\end{adjustbox}
\end{subfigure} \hfill
} % End visible 1-2
\only<3-4>{%%
\begin{subfigure}[t]{1.0\linewidth}
\caption{Sub caption 2 \label{fig:captionSmallTwo}}
\resizebox{\textwidth}{!}{%
\begin{tikzpicture}[xscale=1.0]
\draw [thick] (0.0, 2.0) -- (10, 2.0);
\node[align=center, above] at (0.9, 2.0)%
{TestS 1};
\draw [thick] (3.0, 2.0) -- (3.0, 3.1);
\node[align=center, above] at (3.0, 3.1)%
{Line 1};
\draw [thick] (6.0, 2.0) -- (6.0, 3.1);
\node[align=center, above] at (6.0, 3.1)%
{Line 2};
\draw [thick] (9.0, 2.0) -- (9.0, 3.1);
\node[align=center, above] at (9.0, 3.1)%
{Line 3};
\draw [fill=green] (3, 2.0) rectangle (6.0, 2.9);
\draw [fill=orange] (3, 0.0) rectangle (3.5, 0.9);
\draw [thick] (0.0, 0.0) -- (10, 0.0);
\node[align=center, above] at (0.9,0.0)%
{Sample 2};
\draw [thick] (3.0,.0) -- (3.0, 2.0);
\draw [thick] (3.5,-.3) -- (3.5,1.1);
\node[align=center, below] at (3.5,-0.3)%
{Line 4};
\draw [thick] (6.5,-.3) -- (6.5,1.1);
\node[align=center, below] at (6.5,-0.3)%
{Line 5};
\draw [thick] (9.5,-.3) -- (9.5,1.1);
\node[align=center, below] at (9.5,-0.3)%
{Line 6};
\draw [->,thick] (3.3, 4.2) -- (3.3, 3.7);
\node[align=center, above] at (3.2, 4.1)%
{Event 2};
\draw [thick, dashed] (6.0, 2.0) -- (3.5, 1.1);
\draw [thick, dashed] (3.3, 0.0) -- (3.3, 3.6);
\end{tikzpicture}
}%
%\end{adjustbox}
\end{subfigure} \hfill
} % End visible 3-4
\captionsetup{justification=centering} %Center a two line caption
\caption{The big caption} \protect\label{fig:big}
\end{figure}
\end{column}
\end{overlayarea}
\end{columns}
\end{frame}
\end{document}
评论
您无需使用两个单独的
tikzpicture
环境,只需使用一个环境,而且 TikZ 的构造具有叠加感知功能。这将大大缩短代码,并解决图像跳跃的问题。请注意,不建议将该
subcaption
包与 一起使用beamer
;您应该使用subfig
相反;无论如何,如果您决定使用subcaption
,则需要使用caption
模式compatibility=false
,因此请像这样加载包:\usepackage[compatibility=false]{caption} \usepackage{subcaption}