我使用 tikz 包创建了一个多边形。我需要更改文本的背景颜色,使其与幻灯片的背景颜色相匹配。我附上了照片。
\begin{figure} [H]
\begin{center}
\begin{tikzpicture} [scale=0.4]
\tikzstyle{every node}=[draw,circle,fill=white,minimum size=1pt,
inner sep=0pt]
\draw node (1) [label=$v_{1,1}$] {}
-- ++(330:2.0cm) node [](2) [] {}
-- ++(270:2.0cm) node (3)
[] {}-- ++(210:2.0cm) node (4)
[] {}-- ++(150:2.0cm) node (5)
[] {}-- ++(90:2.0cm) node (6)
[] {}-- ++(30:2.0cm) node (1)
{};
\path [](1) edge (2);
\path [](2) edge (3);
\path [dashed](3) edge (4);
\path (4) edge (5);
\path (5) edge (6);
\path [](6) edge (1);
\draw (4) node[below,xshift=0mm,draw=white]{Layer 1};
\draw (1) node[below,yshift=-5mm,draw=white]{$K_n$};
\end{tikzpicture}
\end{center}
\caption{$K_n \square P_3$}
\label{3}
\end{figure}
答案1
背景颜色可以使用以下名称bg
:
\documentclass{beamer}
\usepackage{tikz}
\setbeamercolor{background canvas}{bg=orange!50!white}
\begin{document}
\begin{frame}
\begin{tikzpicture} [scale=0.4]
\usebeamercolor{background canvas}
\tikzset{every node/.style={draw,minimum size=1pt,
inner sep=0pt}}
\draw node (1) [label=$v_{1,1}$] {}
-- ++(330:2.0cm) node [](2) [] {}
-- ++(270:2.0cm) node (3)
[] {}-- ++(210:2.0cm) node (4)
[] {}-- ++(150:2.0cm) node (5)
[] {}-- ++(90:2.0cm) node (6)
[] {}-- ++(30:2.0cm) node (1)
{};
\path [](1) edge (2);
\path [](2) edge (3);
\path [dashed](3) edge (4);
\path (4) edge (5);
\path (5) edge (6);
\path [](6) edge (1);
\draw (4) node[below,xshift=0mm,draw=bg]{Layer 1};
\draw (1) node[below,yshift=-5mm,draw=bg]{$K_n$};
\end{tikzpicture}
\end{frame}
\end{document}
答案2
比用与背景颜色匹配的纯色填充这些节点更好的方法是不填充节点。这样,如果背景颜色发生变化,代码仍然是正确的。
为此,您只需删除这些节点的fill=white
和draw=white
选项。这样,就不会发生填充或绘制。
要在六边形的顶点处画小点,可以使用every node/.style
范围。另外,不要\draw
对六边形使用 ,而要使用\path
,因为边缘是稍后绘制的。
这是我建议的代码:
\documentclass{beamer}
\usepackage{tikz}
\setbeamercolor{background canvas}{bg=orange!50!white}
\begin{document}
\begin{frame}
\begin{center}
\begin{tikzpicture}[scale=0.4]
\begin{scope}[every node/.style={circle,minimum size=2pt,
inner sep=0pt, fill}]
\path node (1) [label=$v_{1,1}$] {}
-- ++(330:2.0cm) node [](2) [] {}
-- ++(270:2.0cm) node (3)
[] {}-- ++(210:2.0cm) node (4)
[] {}-- ++(150:2.0cm) node (5)
[] {}-- ++(90:2.0cm) node (6)
[] {}-- ++(30:2.0cm) node (1)
{};
\end{scope}
\path [](1) edge (2);
\path [](2) edge (3);
\path [dashed] (3) edge (4);
\path (4) edge (5);
\path (5) edge (6);
\path [](6) edge (1);
\draw (4) node[below,xshift=0mm,]{Layer 1};
\draw (1) node[below,yshift=-5mm]{$K_n$};
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
更新。与您的问题无关,但利用这个机会,您的代码可以重构为使用循环和自定义样式,使其更短并且(恕我直言)更具可读性:
\documentclass{beamer}
\usepackage{tikz}
\setbeamercolor{background canvas}{bg=orange!50!white}
\begin{document}
\begin{frame}
\begin{center}
\tikzset{
smalldot/.style={circle,minimum size=2pt, inner sep=0pt, fill}
}
\begin{tikzpicture}[scale=0.4]
\foreach \angle [count=\n from 1] in {30, 90, ..., 330}
\node[smalldot] (\n) at (\angle:2cm) {};
\draw (6) -- (1) -- (2) -- (3) -- (4) -- (5);
\draw [dashed] (5) -- (6);
\node[above] at (2) {$v_{1,1}$};
\node[below] at (5) {Layer 1};
\node at (0,0) {$K_n$};
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}