![如何使一些边缘更厚并呈现不同的颜色?](https://linux22.com/image/433142/%E5%A6%82%E4%BD%95%E4%BD%BF%E4%B8%80%E4%BA%9B%E8%BE%B9%E7%BC%98%E6%9B%B4%E5%8E%9A%E5%B9%B6%E5%91%88%E7%8E%B0%E4%B8%8D%E5%90%8C%E7%9A%84%E9%A2%9C%E8%89%B2%EF%BC%9F.png)
我有以下 TikZ 代码。我想使一些边缘更厚,并将其颜色更改为红色,但仅限于第二个覆盖层。您该怎么做?
\documentclass{beamer}
\usepackage[beamer,customcolors]{hf-tikz}
\usepackage{tikz}
\usepackage{tcolorbox}
\usetikzlibrary{arrows.meta, tikzmark, chains, fit,
shapes}
\begin{document}
\begin{frame}
\definecolor{myblue}{RGB}{80,80,160}
\definecolor{mygreen}{RGB}{80,160,80}
\begin{tcolorbox}[colback=white, text width=8.5cm]
\begin{tikzpicture}[thick,
every node/.style={draw,circle},
fsnode/.style={fill=myblue},
ssnode/.style={fill=mygreen}
]
\begin{scope}[every node/.style={circle,thick,draw}]
\node (A) at (0,0) {};
\node (B) at (0,3) {};
\node (C) at (3,0) {};
\node (D) at (3,3) {};
\node (E) at (4.5, 1.5) {};
\node (F) at (-3, 3) {};
\end{scope}
\begin{scope}[>={Stealth[black]},
every node/.style={fill=white,circle},
every edge/.style={draw=red,very thick}]
\path [-] (A) edge (B);
\path [-] (A) edge (C);
\path [-] (B) edge (D);
\path [-] (D) edge (C);
\path [-] (D) edge (E);
\path [-] (C) edge (E);
\path [-] (F) edge (B);
\end{scope}
\end{tikzpicture}
\end{tcolorbox}
\end{frame}
\end{document}
答案1
您可以使用alt
中的样式overlay-beamer-styles
。它允许您在特定叠加层上切换样式。在此示例中,我使用
subvert/.style={alt=<#1>{every edge/.style={draw=blue,ultra thick}}{}}
改变给定覆盖层上的边缘样式。
\documentclass{beamer}
\usepackage[beamer,customcolors]{hf-tikz}
\usepackage{tikz}
\usepackage{tcolorbox}
\usetikzlibrary{arrows.meta, tikzmark, chains, fit,
shapes,overlay-beamer-styles}
\begin{document}
\begin{frame}[fragile]
\definecolor{myblue}{RGB}{80,80,160}
\definecolor{mygreen}{RGB}{80,160,80}
\begin{tcolorbox}[colback=white, text width=8.5cm]
\begin{tikzpicture}[thick,
every node/.style={draw,circle},
fsnode/.style={fill=myblue},
ssnode/.style={fill=mygreen}
% every fit/.style={ellipse,draw,inner sep=-2pt,text width=2cm},
% ->,shorten >= 3pt,shorten <= 3pt
]
\begin{scope}[every node/.style={circle,thick,draw}]
\node (A) at (0,0) {};
\node (B) at (0,3) {};
\node (C) at (3,0) {};
\node (D) at (3,3) {};
\node (E) at (4.5, 1.5) {};
\node (F) at (-3, 3) {};
\end{scope}
\begin{scope}[>={Stealth[black]},
every node/.style={fill=white,circle},
every edge/.style={draw=red,very thick},
subvert/.style={alt=<#1>{every edge/.style={draw=blue,ultra thick}}{}}]
\path [-] (A) edge (B);
\path [-,subvert=2] (A) edge (C);
\path [-] (B) edge (D);
\path [-,subvert=2] (D) edge (C);
\path [-,subvert=2] (D) edge (E);
\path [-] (C) edge (E);
\path [-] (F) edge (B);
\end{scope}
\end{tikzpicture}
\end{tcolorbox}
\end{frame}
\end{document}