# Define text color for all tikz nodes of a particular type

I want a particular node type in tikz to have a specific text color. Currently, I have defined a macro for text color. But I need to keep using that macro at every node.

Is not there a better solution? So, just like defining backgrond color for a node, we can also define text color in \tikzstyle statement?

Here is the 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}


You can use text=LemonChiffon option to specify the text color along with the font= option to apply \bfseries. Below, I have replaced the \whttxt macro with the whttxt option to apply these two:

## Code:

\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}

• The last font=\bfseries option seems redundant... – Paul Gaborit Dec 11 '14 at 6:56
• @PaulGaborit: Thanks for pointing that out. It was left over from before I defined the whttxt style. Have fixed it now. – Peter Grill Dec 11 '14 at 7:18