Quiero que un tipo de nodo particular en tikz tenga un color de texto específico. Actualmente, he definido una macro para el color del texto. Pero necesito seguir usando esa macro en cada nodo.
¿No existe una solución mejor? Entonces, al igual que definir el color de fondo de un nodo, ¿también podemos definir el color del texto en \tikzstyle
la declaración?
Aquí está el 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}
Respuesta1
Puede usar text=LemonChiffon
la opción para especificar el color del texto junto con la font=
opción para aplicar \bfseries
. A continuación, reemplacé la \whttxt
macro con la whttxt
opción de aplicar estos dos:
Notas:
- Deberías usar
\tikzset
en lugar de\tikzstyle
según¿Debería usarse \tikzset o \tikzstyle para definir los estilos de TikZ?.
Código:
\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}