
コマンドにオプションを設定することは可能ですか\usetikzlibrary
? オプションがアクティブになったときに異なるスタイルを定義したいと思います。例:
\usetikzlibrary[blue]{something}
\usetikzlibrary[green]{something}
\usetikzlibrary[red]{something}
同じものを異なる色で定義する
\tikzset{C/.style={thick, circle, fill=red}};
ありがとう。
答え1
percusse と cfr のコメントにあるように、tikz ライブラリのオプションは使用できません。また、マニュアルには、中括弧を角括弧に置き換えることができると書かれています (ConTeXt 固有)。
ハンドラを使用してオプションを設定する方法の例を次に示します.is choice
。
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
% ----------- code to put in your tikzlibrarysomething.code.tex
\tikzset{
C/.style={ultra thick, circle},
theme/.is choice,
theme/ocean/.style={C/.append style={draw=none,fill=blue!50}},
theme/fire/.style={C/.append style={draw=orange,fill=red}},
theme/nature/.style={C/.append style={draw=brown,fill=green!70}},
theme = fire % <- set the default theme
}
%------------- then to use
% \usetikzlibrary{something}
\tikzset{theme=ocean}
%------------- and here we are
\begin{document}
\tikz \node[C] {Test};
\end{document}
編集:cfr のコメントを受けて、コードをより「自明」なものに変更しました。
答え2
これはKpymの回答をアレンジしたものです。Kpymの解決策はあなたが述べた要望に近いですが、私の解決策はより短く、選択できる点でより柔軟です。どれでも色。
\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{calc}
\tikzset{
C/.style={circle},
theme color/.style={C/.append style={fill=#1!50}},
}
\tikzset{theme color=magenta}
\begin{document}
\tikz \node[C] {Test};
\end{document}
ただし、不透明度を調整するオプションを含める必要がある場合があり、ユーザー (おそらくあなた) が色などを設定することを忘れた場合に備えて、デフォルトが設定されるようにしておくのがおそらく最善です。
以下はクラウディオ・フィアンドリーノの回答色と不透明度のデフォルトを設定し、それらを上書きするオプションがあります。プリアンブルで使用する場合は、\makeatletter... \makeatother
のため で囲む必要があり@
ます。ライブラリ コードで使用する場合、これは必要ありません。
\tikzset{
C/.style={circle, fill=\my@theme@color!\my@theme@color@opacity},
theme color/.store in=\my@theme@color,
theme color opacity/.store in=\my@theme@color@opacity,
theme settings/.code={%
\tikzset{#1}},
theme color=blue,% set a default
theme color opacity=50,% set a default
}
何もしなければ、不透明度 50% の青い円が表示されます。ただし、プリアンブルで上書きすることで、これらのデフォルトを変更できます。
\tikzset{theme settings={theme color=magenta, theme color opacity=75}}
これにより、75% の不透明度で塗りつぶされたマゼンタ色の円が表示されます。または、特定のノードまたはscope
画像内の特定のノードに対して上書きすることもできます。
\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{calc}
\makeatletter
\tikzset{% https://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
C/.style={circle, align=center, fill=\my@theme@color!\my@theme@color@opacity},
theme color/.store in=\my@theme@color,
theme color opacity/.store in=\my@theme@color@opacity,
theme settings/.code={%
\tikzset{#1}},
theme color=blue,% set a default
theme color opacity=50,% set a default
}
\makeatother
\tikzset{theme settings={theme color=magenta, theme color opacity=75}}
\begin{document}
\begin{tikzpicture}
\node[C] {Preamble\\Config};
\begin{scope}[theme settings={theme color=yellow, theme color opacity=100}]
\node [C, xshift=15mm] {Scope\\Config};
\end{scope}
\node [C, theme color=green, theme color opacity=15, xshift=29mm] {Node\\Config};
\end{tikzpicture}
\end{document}