為特定類型的所有 tikz 節點定義文字顏色

為特定類型的所有 tikz 節點定義文字顏色

我希望 tikz 中的特定節點類型具有特定的文字顏色。目前,我已經為文字顏色定義了一個巨集。但我需要在每個節點繼續使用該巨集。

難道沒有更好的解決方法嗎?那麼,就像定義節點的背景顏色一樣,我們也可以在\tikzstyle語句中定義文字顏色嗎?

這是 MWE:

\documentclass{article}

\usepackage[svgnames]{xcolor}                                                                                                         
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\newcommand{\whttxt}[1]{\textbf{\textcolor{LemonChiffon}{#1}}}
\begin{document}
\pagestyle{empty}

% Define block styles
\tikzstyle{block} = [rectangle, draw, fill=black, text width=5em, text centered, rounded corners, minimum height=4em]

\begin{tikzpicture}[node distance=1in]
  \node [block] (nodea) {\whttxt{Node A}};
  \node [block, below of=nodea] (nodeb) {\whttxt{Node B}};
\end{tikzpicture}

\end{document}

答案1

您可以使用text=LemonChiffon選項來指定文字顏色以及font=要套用的選項\bfseries。下面,我\whttxtwhttxt應用這兩個選項的選項取代了巨集:

在此輸入影像描述

筆記:

代碼:

\documentclass{article}

\usepackage[svgnames]{xcolor}                                                                                                         
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
%\newcommand{\whttxt}[1]{\textbf{\textcolor{LemonChiffon}{#1}}}

\begin{document}
\pagestyle{empty}

% Define block styles
%\tikzstyle{block} = [rectangle, draw, fill=black, text width=5em, text centered, rounded corners, minimum height=4em]
\tikzset{block/.style={rectangle, draw, fill=black, text width=5em, text centered, rounded corners, minimum height=4em}}
\tikzset{whttxt/.style={text=LemonChiffon, font=\bfseries}}

\begin{tikzpicture}[node distance=1in]
  \node [block, whttxt] (nodea) {Node A};
  \node [block, below of=nodea, whttxt] (nodeb) {Node B};
\end{tikzpicture}

\end{document}

相關內容