(几乎最小的)工作示例:
\documentclass{beamer}
\usepackage{tikz}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}
\begin{document}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{frame}
\frametitle{Parallel Boruvka's}
\tikzstyle{vertex}=[circle,fill=black!25,minimum size=20pt,inner sep=0pt]
\tikzstyle{selected vertex} = [vertex, fill=red!24]
\tikzstyle{root} = [vertex, fill=blue!24]
\tikzstyle{edge} = [draw,thick,-]
\tikzstyle{weight} = [font=\small]
\tikzstyle{selected edge} = [draw,line width=5pt,-,red!50]
\tikzstyle{dfs} = [draw,line width=5pt,-,blue!20]
\begin{figure}
\begin{tikzpicture}[scale=1.8, auto,swap]
\foreach \pos/\name/\fr in {{(0,1)/1/1},{(0,1)/2/3}, {(1,1)/2/1}, {(2,1)/3/1}, {(2,1)/2/3}}
\node<\fr->[vertex] (\name) at \pos {$\name$};
\foreach \source/ \dest /\weight in {1/2/3,2/3/1}
\path[edge] (\source) -- node[weight] {$\weight$} (\dest);
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
第二张和第三张幻灯片上的输出:
我想要实现的是,所有顶点的 ID 与幻灯片 3 上的相同,但边权重与幻灯片 2 上的相同。这能做到吗?
一个(愚蠢的)附带问题:在哪里可以找到对我有帮助的文档?/我所能找到的只是一些例子,但没有真正的解释。
答案1
您正在为不同幻灯片上的不同节点指定名称2
。为避免这种情况,请对节点进行唯一标记,即使节点内容相同:
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\frametitle{Parallel Boruvka's}
\tikzset{
vertex/.style = {circle,fill=black!25,minimum size=20pt,inner sep=0pt},
edge/.style = {draw,thick,-},
weight/.style = {font=\small},
}
\begin{figure}
\begin{tikzpicture}[scale=1.8, auto,swap]
\foreach \pos/\name/\fr/\label in {{(0,1)/1/1/1},{(0,1)/2/3/2a}, {(1,1)/2/1/2}, {(2,1)/3/1/3}, {(2,1)/2/3/2b}}
\node<\fr->[vertex] (\label) at \pos {$\name$};
\foreach \source/ \dest /\weight in {1/2/3,2/3/1}
\path[edge] (\source) -- node[weight] {$\weight$} (\dest);
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
请注意,您应该使用\tikzset
而不是,\tikzstyle
因为后者已被弃用。