如何为 Tikzforeach 子列中的不同项目着色?

如何为 Tikzforeach 子列中的不同项目着色?

我不太清楚如何解释我在寻找什么,但我得到了一个两列框架。在左侧,有一个 tikzfigure,显示了 6 个 beamer 页面上的图形算法。在右侧列中,我有算法的描述,我想为显示的图形上我刚刚使用的步骤着色。

\documentclass{beamer}

\usepackage{tikz}
\usetheme{CambridgeUS}
\usepackage{verbatim}
\usepackage{xcolor}

\begin{document}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}


\begin{frame}

\begin{columns}
\begin{column}{0.5\textwidth}


\usetikzlibrary{arrows,shapes}
\tikzstyle{vertex}=[circle,fill=blue!40,minimum size=20pt,inner sep=0pt]
\tikzstyle{selected vertex} = [vertex, fill=blue!60]
\tikzstyle{edge} = [draw,thick,-]
\tikzstyle{weight} = [font=\small]
\tikzstyle{edge1} = [draw,line width=5pt,-,blue!40]

\begin{figure}
\begin{tikzpicture}[scale=1.8, auto,swap]  

\foreach \pos/\name in {{(1,1)/a}, {(2,2)/b}, {(4,2)/c},
                        {(2,0)/d}, {(4,0)/e}, {(3,1)/f}}
    \node[vertex] (\name) at \pos {$\name$};

\foreach \source/ \dest /\weight in {b/a/1, c/b/6, d/a/11, f/a/4,
                                     f/b/6, e/c/3, e/d/1,
                                     f/d/10, e/f/9, c/f/7}                                       
    \path[edge] (\source) -- node[weight, sloped] {$\weight$} (\dest);

\foreach \vertex / \fr in {a/1,b/2,c/3,e/3,d/4,f/5}
    \path<\fr-> node[selected vertex] at (\vertex) {$\vertex$};

\begin{pgfonlayer}{background}
   \pause
   \foreach \source / \dest in {b/a}       
       \path<+->[edge1] (\source.center) -- (\dest.center);
   \foreach \source / \dest in {c/e,d/e}       
       \path<+->[edge1] (\source.center) -- (\dest.center);
   \foreach \source / \dest in {a/f}       
       \path<+->[edge1] (\source.center) -- (\dest.center);        
   \foreach \source / \dest in {b/c}       
       \path<+->[edge1] (\source.center) -- (\dest.center);    
       \path<+->[edge1] (b) -- (a) (f) -- (a) (e) -- (c) (d) -- (e);


\end{pgfonlayer}
\end{tikzpicture}
\end{figure}   

\end{column}
\begin{column}{0.5\textwidth}  
\begin{flushleft}        

 \begin{itemize}[<1-| alert@+>]
    \item [1.]task1 \\
    \item [2.]task2 \\
    \item [3.]task3 \\
 \end{itemize}
\end{flushleft}
\end{column}
\end{columns}


\end{frame}
\end{document}

答案1

我必须承认我不太明白你想在哪个步骤为哪个项目着色,但可能最简单的方法是手动完成,例如\item<alert@2->将从幻灯片 2 到末尾提醒该项目。

\documentclass{beamer}

\usepackage{tikz}
\usetheme{CambridgeUS}
\usepackage{verbatim}
\usepackage{xcolor}

\begin{document}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}


\begin{frame}

\begin{columns}
\begin{column}{0.5\textwidth}


\usetikzlibrary{arrows,shapes}
\tikzset{vertex/.style={circle,fill=blue!40,minimum size=20pt,inner sep=0pt}}
\tikzset{selected vertex/.style={vertex, fill=blue!60}}
\tikzset{edge/.style={draw,thick,-}}
\tikzset{weight/.style={font=\small}}
\tikzset{edge1/.style={draw,line width=5pt,-,blue!40}}

\begin{figure}
\begin{tikzpicture}[scale=1.8, auto,swap]  

\foreach \pos/\name in {{(1,1)/a}, {(2,2)/b}, {(4,2)/c},
                        {(2,0)/d}, {(4,0)/e}, {(3,1)/f}}
    \node[vertex] (\name) at \pos {$\name$};

\foreach \source/ \dest /\weight in {b/a/1, c/b/6, d/a/11, f/a/4,
                                     f/b/6, e/c/3, e/d/1,
                                     f/d/10, e/f/9, c/f/7}                                       
    \path[edge] (\source) -- node[weight, sloped] {$\weight$} (\dest);

\foreach \vertex / \fr in {a/1,b/2,c/3,e/3,d/4,f/5}
    \path<\fr-> node[selected vertex] at (\vertex) {$\vertex$};

\begin{pgfonlayer}{background}
   \foreach \source / \dest in {b/a}       
       \path<+(1)->[edge1] (\source.center) -- (\dest.center);
   \foreach \source / \dest in {c/e,d/e}       
       \path<+(1)->[edge1] (\source.center) -- (\dest.center);
   \foreach \source / \dest in {a/f}       
       \path<+(1)->[edge1] (\source.center) -- (\dest.center);        
   \foreach \source / \dest in {b/c}       
       \path<+(1)->[edge1] (\source.center) -- (\dest.center);    
       \path<+(1)->[edge1] (b) -- (a) (f) -- (a) (e) -- (c) (d) -- (e);


\end{pgfonlayer}
\end{tikzpicture}
\end{figure}   

\end{column}
\begin{column}{0.5\textwidth}  
\begin{flushleft}        

 \begin{itemize}
    \item<alert@2-> [1.]task1 \\
    \item [2.]task2 \\
    \item<alert@3-> [3.]task3 \\
 \end{itemize}
\end{flushleft}
\end{column}
\end{columns}


\end{frame}
\end{document}

在此处输入图片描述

相关内容