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
置き換えました。\whttxt
whttxt
ノート:
\tikzset
代わりに\tikzstyle
次のように使用してくださいTikZ スタイルを定義するには、\tikzset または \tikzstyle を使用する必要がありますか?。
コード:
\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}