usetikzlibrary의 옵션

usetikzlibrary의 옵션

명령 에 대한 옵션을 가질 수 있습니까 \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}

관련 정보