特定のタイプのすべての 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=オプションを適用することもできます。以下では、マクロを、これら 2 つを適用するオプションに\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}

関連情報