在 TikZ 中覆盖节点的选项

在 TikZ 中覆盖节点的选项

我使用它是\foreach为了简化手动设置具有特定样式的节点的任务,但我想随后更改一些节点的选项。

\documentclass{article}
\usepackage{tikz}

\begin{document}

\pgfset{
  foreach/parallel foreach/.style args={#1in#2via#3}{evaluate=#3 as #1 using {{#2}[#3-1]}},
}

\begin{tikzpicture}[ultra thick, scale=2.5,
x={({cos(-20)},{-sin(-20)},0)},z={({-sin(-35)},{-cos(-35)},0)}]
\def\y{0.5}
\def\vertecislist{{0,0,1},{1,0,1},{2,0,1},{0,0,0},{1,0,0},{2,0,0},{0,\y,1},{1,\y,1},{2,\y,1},{0,\y,0},{1,\y,0},{2,\y,0}}
\def\nodeslist{1, 2, 4, 3, 6, 12, 7, 14, 28, 21, 42, 84}
\foreach \pos [count=\Ind,
  parallel foreach=\l in \nodeslist via \Ind]
  in \vertecislist
  {
    \node[circle,inner sep=2pt,outer sep=0pt,fill=black,
        label=\ifnum\Ind<7 below\else above\fi:\l](p\l) at (\pos){};
  }
  
  \draw (p84)edge(p12)edge(p28)--(p42)edge(p6)edge(p14)--
      (p21)edge(p7)--(p3)edge(p6)--(p1)edge(p2)--
      (p7)--(p14)edge(p28)--(p2)edge(p6)--(p4)edge(p28)--(p12)--(p6);
\end{tikzpicture}

\end{document}

在此处输入图片描述

这种方法好像不行:

\draw (p84) node[label=90:$84$]{} edge(p12)edge(p28)--(p42)node[fill=red]{}edge(p6)edge(p14)--
      (p21)edge(p7)--(p3)edge(p6)--(p1)edge(p2)--
      (p7)--(p14)edge(p28)node[fill=red]{}--(p2)edge(p6)--(p4)edge(p28)--(p12)--(p6);

(p#)定义后,有没有办法更改?我需要更改(p28)填充颜色和标签角度(p84)

答案1

一旦绘制了节点,就无法取消绘制,因此唯一的解决方案就是在其上绘制。

平行六面体上的节点

\documentclass{article}
\usepackage{tikz}

\begin{document}

\tikzset{rnode/.style={circle,red,fill=red,outer sep=0pt,inner sep=2pt}}

\pgfset{
  foreach/parallel foreach/.style args={#1in#2via#3}{evaluate=#3 as #1 using {{#2}[#3-1]}},
}

\begin{tikzpicture}[ultra thick, scale=2.5,
x={({cos(-20)},{-sin(-20)},0)},z={({-sin(-35)},{-cos(-35)},0)}]
\def\y{0.5}
\def\vertecislist{{0,0,1},{1,0,1},{2,0,1},{0,0,0},{1,0,0},{2,0,0},{0,\y,1},{1,\y,1},{2,\y,1},{0,\y,0},{1,\y,0},{2,\y,0}}
\def\nodeslist{1, 2, 4, 3, 6, 12, 7, 14, 28, 21, 42, 84}
\foreach \pos [count=\Ind,
  parallel foreach=\l in \nodeslist via \Ind]
  in \vertecislist
  {
    \node[circle,inner sep=2pt,outer sep=0pt,fill=black,
        label=\ifnum\Ind<7 below\else above\fi:\l](p\l) at (\pos){};
  }
  
  \draw (p84)edge(p12)edge(p28)--(p42)edge(p6)edge(p14)--(p21)edge(p7)--(p3)edge(p6)--(p1)edge(p2)--(p7)--(p14)edge(p28)--(p2)edge(p6)--(p4)edge(p28)--(p12)--(p6);
      
   \path (p28) node[rnode]{} -- (p42) node[rnode]{};
   \path (p84) node[above=3pt,circle,fill=white,inner sep=5pt]{} node[above right]{84};
\end{tikzpicture}

\end{document}

相关内容