我不知道为什么,但我无法\onslide
在 tikz 节点内使用,否则会出现错误ERROR: Package tikz Error: Giving up on this path. Did you forget a semicolon?.
。知道为什么吗?
梅威瑟:
\documentclass[beamer,tikz,preview]{standalone}
\begin{document}
\begin{standaloneframe}
\begin{tikzpicture}
% Works:
\onslide<+>{\node[]{ABC};}
\onslide<+>{\node[]{ABCDEF};}
% Does not work:
\node[]{\onslide<+->{ABC}\onslide<+->{DEF}};
\end{tikzpicture}
\end{standaloneframe}
\end{document}
-- 编辑 -- 由于我的问题似乎被误解了,我做了一个更好的(带评论的) MWE,第一个结果不是我期望的,而我想要的结果是后来的,但我想要一个更好的解决方案(我不喜欢复制/粘贴东西)。
\documentclass[beamer,tikz,preview]{standalone}
\usetikzlibrary{positioning,overlay-beamer-styles}
\begin{document}
\begin{standaloneframe}
\begin{tikzpicture}[
mynode/.style={
fill=blue!50,
draw,
rectangle,
rounded corners
}
]
% Bad result, the node does not have the same size in all slides,
% and also I can't refer to the value at the step before so I get
% ABCJKL instead of ABCDEFGHIJKL
\def\mycontents{ABC}
\only<2>{\xdef\mycontents{\mycontents DEF}}
\only<3>{\xdef\mycontents{\mycontents GHI}}
\only<4>{\xdef\mycontents{\mycontents JKL}}
\node[mynode]{\mycontents};
% Good result that "simulate" the \uncover, but it is too verbose
% especially when I need to uncover lot's of things inside
% (I don't like to copy/paste stuff)
\node<5>[mynode]{ABC\phantom{DEFGHIJKL}};
\node<6>[mynode]{ABCDEF\phantom{GHIJKL}};
\node<7>[mynode]{ABCDEFGHI\phantom{JKL}};
\node<8>[mynode]{ABCDEFGHIJKL};
%% The syntax I'd love to use:
%% \node[mynode]{\uncover<5->{ABC}\uncover<6->{DEF}\uncover<7->{GHI}\uncover<8->{JKL}}
\end{tikzpicture}
\end{standaloneframe}
\end{document}
答案1
感谢您澄清您想要什么。您只需添加括号。
\documentclass[beamer,tikz,preview]{standalone}
\begin{document}
\begin{standaloneframe}
\begin{tikzpicture}
% Works:
\node{{\onslide<+->{ABC}\onslide<+->{DEF}}};
\end{tikzpicture}
\end{standaloneframe}
\end{document}