我在更新 Beamer 演示文稿中的 tikz 块标签时遇到了问题。到目前为止,我一直在使用\onslide
代码更新块大小和位置这个答案。对于标签文本,\onslide
上下移动内容(如预期)。\only
标签文本是否稍微水平移动?
\documentclass[pd,xcolor={dvipsnames}]{beamer}
\usetheme{Frankfurt}
\usepackage[absolute,overlay]{textpos}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,backgrounds,positioning,patterns}
\tikzset{onslide/.code args={<#1>#2}{%
\only<#1>{\pgfkeysalso{#2}} % \pgfkeysalso doesn't change the path
}}
\begin{document}
\begin{frame}
\centering
\tikzstyle{blocka} = [text width=3.0em, text centered, rectangle, rounded corners, fill, fill=red]
\tikzstyle{every node}=[font=\boldmath,color=white]
\tikzstyle{ann} = [draw=none,fill=white,rounded corners]
\begin{tikzpicture}
\node[blocka,
onslide=<1-2>{minimum height=10.00em},
onslide=<3-4>{minimum height=8.00em},
onslide=<5>{minimum height=7.67em},
onslide=<2-3>{pattern=crosshatch,pattern color=red}] (Aa1) {
\only<1>{$100$}
\only<2-3>{ }
\only<4>{$80$}
\only<5->{$76.7$}
%\onslide<1>{$100$},
%\onslide<2-3>{ },
%\onslide<4>{$80$},
%\onslide<5->{$76.7$};
};
\node[ann, left=0.25em of Aa1.180, color=red, fill=white] {A};
\end{tikzpicture}
\end{frame}
\end{document}
答案1
如果您希望按 Enter 键换行,则命令\only<>{}
后面应跟一个%
- 符号。在 LaTeX 中,换行被解释为空格。此空格位于数字前面,因此将其移出中心。
% arara: pdflatex
\documentclass{beamer}
\usetheme{Frankfurt}
\usepackage{tikz}
\usetikzlibrary{positioning,patterns}
\tikzset{%
,onslide/.code args={<#1>#2}{\only<#1>{\pgfkeysalso{#2}}}
,every node/.style={font=\boldmath,color=white}
,blocka/.style={text width=3.0em, text centered, rectangle, rounded corners, fill, fill=red}
,ann/.style={draw=none,fill=white,rounded corners}
}
\begin{document}
\begin{frame}
\begin{center}
\begin{tikzpicture}
\node[blocka,
onslide=<1-2>{minimum height=10.00em},
onslide=<3-4>{minimum height=8.00em},
onslide=<5>{minimum height=7.67em},
onslide=<2-3>{pattern=crosshatch,pattern color=red}] (Aa1) {%
\only<1>{$100$}% <= this one centeres the first slide
\only<2-3>{ }% <= this one centeres the fourth slide
\only<4>{$80$}% <= this one centeres the fifth slide
\only<5->{$76.7$}%
};
\node[ann, left=0.25em of Aa1.180, color=red, fill=white] {A};
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}