带颜色节点的 Tikz 矩阵(交通灯)

带颜色节点的 Tikz 矩阵(交通灯)

我正在尝试调整交通灯命令(从之前问题的一些答案中找到),使得节点(圆圈)的边框变为黑色(draw = black!100里面的线nodes),但似乎draw = black!100没有任何改变。

\documentclass[a4paper,fontsize=12pt]{article}

\usepackage{tikz}
\usetikzlibrary{fit, matrix, positioning}

\newcommand\trafficlight[3]
{
    \begin{tikzpicture}[baseline=-1.5mm]
        \matrix (m) [matrix of nodes,
        ampersand replacement = \&,
        rounded corners,
        draw = blue!100,
%       fill = blue!30,
        column sep = 1.5mm,                  
        nodes = {circle, draw = black!100, fill = #1, minimum size = 5mm, inner sep = 0mm,
            anchor = center},
        ]
        {
            |[#1]| \& |[#2]| \& |[#3]| \\
        };
    \end{tikzpicture}
}

\begin{document}

\trafficlight{red}{yellow}{green}

\end{document}

我将非常感激任何帮助!

答案1

|[#1]|设置绘制和填充颜色。尝试:


\documentclass[a4paper,fontsize=12pt]{article}

\usepackage{tikz}
\usetikzlibrary{fit, matrix, positioning}

\newcommand\trafficlight[3]
{
    \begin{tikzpicture}[baseline=-1.5mm]
        \matrix (m) [matrix of nodes,
        ampersand replacement = \&,
        rounded corners,
        draw = blue,
%       fill = blue!30,
        column sep = 1.5mm,
        nodes = {circle, draw = black, fill = #1, minimum size = 5mm, inner sep = 0mm,
            anchor = center},
        ]
        {
            |[fill=#1]| \& |[fill=#2]| \& |[fill=#3]| \\
        };
    \end{tikzpicture}
}

\begin{document}

\trafficlight{red}{yellow}{green}

\end{document}

顺便说一句,fontsize不是一个有效的选项(12pt是),并且black!100与 相同black。此外,您的宏在 周围添加了几个空格...

在此处输入图片描述

相关内容