我喜欢定义一堆坐标,然后从中创建所需图表的想法,但现在我遇到了以下问题。下面的 MWE 演示了这一点:连接两个节点的箭头被节点的内容部分隐藏。我只想分阶段显示图表(通过\onslide
),这就是为什么我没有直接用坐标定义节点。
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}{MWE}
\begin{tikzpicture}
\foreach \y in {0,1,...,9}
{
\coordinate (A\y) at (0,{-1*\y});
\coordinate (B\y) at (7,{-1*\y});
}
\onslide<+->{\draw (A0) node{aaaa};}
\onslide<+->{\draw (A1) node{bbbb};}
\onslide<+->{\draw (A2) node{cccc};}
\onslide<+->{\draw[->] (A2)--(B2) node{dddd};}
\end{tikzpicture}
\end{frame}
\end{document}
答案1
最简单的方法是使用命名节点,而不是帮助您放置节点的坐标,只需链条和/或我们最喜欢的visible on
风格。
代码A
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}{MWE}
\begin{tikzpicture}
\foreach \y in {0,1,...,9}
{
\coordinate (A\y) at (0,{-1*\y});
\coordinate (B\y) at (7,{-1*\y});
}
\onslide<+->{\node at (A0) {aaaa};}
\onslide<+->{\node at (A1) {bbbb};}
\onslide<+->{\node at (A2) (nA2) {cccc};}
\onslide<+->{\node at (B2) {dddd} edge[<-] (nA2);}
\end{tikzpicture}
\end{frame}
\end{document}
代码 B1
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{frame}{MWE}
\begin{tikzpicture}[node distance=1cm and 7cm,
start chain=going below,
on grid]
\onslide<+->{\node[on chain] {aaaa};}
\onslide<+->{\node[on chain] {bbbb};}
\onslide<+->{\node[on chain] (nA2) {cccc};}
\onslide<+->{\node[right=of nA2] {dddd} edge[<-] (nA2);}
\end{tikzpicture}
\end{frame}
\end{document}
代码 B2
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\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}}
},
}
\begin{document}
\begin{frame}{MWE}
\begin{tikzpicture}[node distance=1cm and 7cm,
start chain=going below,
on grid]
\node[visible on=<+->,on chain] {aaaa};
\node[visible on=<+->,on chain] {bbbb};
\node[visible on=<+->,on chain] (nA2) {cccc};
\path[visible on=<+->] node[right=of nA2] {dddd} edge[<-] (nA2);
\end{tikzpicture}
\end{frame}
\end{document}