如何仅为电路的一部分着色?

如何仅为电路的一部分着色?

我想为我的部分电路涂上颜色,但 TeXstudio 似乎每次都会卡住。

我的原始代码是:

% Power electronics---converters and inverter
% Author: Ali Mehrizi-Sani
\documentclass{standalone}
\usepackage{siunitx}
\usepackage[american,cuteinductors,smartlabels]{circuitikz}

\usetikzlibrary{calc}
\ctikzset{bipoles/thickness=1}
\ctikzset{bipoles/length=0.8cm}
\ctikzset{bipoles/diode/height=.375}
\ctikzset{bipoles/diode/width=.3}
\ctikzset{tripoles/thyristor/height=.8}
\ctikzset{tripoles/thyristor/width=1}
\ctikzset{bipoles/vsourceam/height/.initial=.7}
\ctikzset{bipoles/vsourceam/width/.initial=.7}
\tikzstyle{every node}=[font=\small]
\tikzstyle{every path}=[line width=0.8pt,line cap=round,line join=round]

\begin{document}
\begin{circuitikz}
    \draw
    (0,0)
    to[V=$V_{in}$, invert] ++(0,2)
    to[short] ++(0.5,0)
    to[short] ++(0.7,0) coordinate(N1)
    to[L] ++(0,-2)
    to[short] (1.2,-.5)
    to[short] (0,-.5)
    to[short] (0,0)

    % ------------------------ Secondary side
    (N1)++(0.7,0) coordinate (N2)

    to[D*] ++(2.5,0) coordinate (C2pos)
    to[C, l_=$C$] ++(0,-2)
    (C2pos)
    to[short] ++(1.5,0)
    to[R, l_=$R$] ++(0,-2)
    to[short] ($(N2)+(0,-2)$)
    to[L] (N2)
    (C2pos)++(2,0)
    to[open, v^>=$v_{out}$] ++(0,-2)
    % ------------------------ Transformer lines
    ($(N1)!0.5!(N2)$)++(-0.05,-0.5)
    -- ++(0,-1) ++(0.1,0) -- ++(0,1)
    ($(N1)+(-0.15,-0.7)$) node[circ] {}
    ($(N2)+(+0.15,-1.3)$) node[circ] {}
    ;
\end{circuitikz}
\end{document} 

成功生成了我的电路,但我无法只对电路的初级侧进行着色

答案1

欢迎来到 TeX.SE!问题是,你在一个路径上绘制了东西,然后几乎不可能改变颜色。但绝对没有必要在一个路径上绘制它。相反,你可以这样做

\documentclass{standalone}
\usepackage{siunitx}
\usepackage[american,cuteinductors,smartlabels]{circuitikz}

\usetikzlibrary{calc}
\ctikzset{bipoles/thickness=1}
\ctikzset{bipoles/length=0.8cm}
\ctikzset{bipoles/diode/height=.375}
\ctikzset{bipoles/diode/width=.3}
\ctikzset{tripoles/thyristor/height=.8}
\ctikzset{tripoles/thyristor/width=1}
\ctikzset{bipoles/vsourceam/height/.initial=.7}
\ctikzset{bipoles/vsourceam/width/.initial=.7}
\tikzstyle{every node}=[font=\small]
\tikzstyle{every path}=[line width=0.8pt,line cap=round,line join=round]

\begin{document}
\begin{circuitikz}
    \draw[red]
    (0,0)
    to[V=$V_{in}$, invert] ++(0,2)
    to[short] ++(0.5,0)
    to[short] ++(0.7,0) coordinate(N1)
    to[L] ++(0,-2)
    to[short] (1.2,-.5)
    to[short] (0,-.5)
    to[short] (0,0);
    % ------------------------ Secondary side
    \draw (N1)++(0.7,0) coordinate (N2)

    to[D*] ++(2.5,0) coordinate (C2pos)
    to[C, l_=$C$] ++(0,-2)
    (C2pos)
    to[short] ++(1.5,0)
    to[R, l_=$R$] ++(0,-2)
    to[short] ($(N2)+(0,-2)$)
    to[L] (N2)
    (C2pos)++(2,0)
    to[open, v^>=$v_{out}$] ++(0,-2);
    % ------------------------ Transformer lines
    \draw($(N1)!0.5!(N2)$)++(-0.05,-0.5)
    -- ++(0,-1) ++(0.1,0) -- ++(0,1)
    ($(N1)+(-0.15,-0.7)$) node[circ] {}
    ($(N2)+(+0.15,-1.3)$) node[circ] {}
    ;
\end{circuitikz}
\end{document} 

在此处输入图片描述

答案2

这类事情的一个根本问题是tikzcircuit 明确绘制路径(而不是准备它),因此draw参数在电路元件中经常不能正确渗透。在这种情况下,我会补充Marmot 的解决方案以下(仅复制电路,其余部分相同):

\begin{circuitikz}
    % color=red colors the components, just "red" only the wires
    % the  every node/.style is needed for the text in symbols
    \begin{scope}[color=red, every node/.style={color=red}]
      \draw[]
      (0,0)
      to[V=$V_{in}$, invert,] ++(0,2)
      to[short] ++(0.5,0)
      to[short] ++(0.7,0) coordinate(N1)
      to[L] ++(0,-2)
      to[short] (1.2,-.5)
      to[short] (0,-.5)
      to[short] (0,0);
    \end{scope}
    % ------------------------ Secondary side
    \draw (N1)++(0.7,0) coordinate (N2)

    to[D*] ++(2.5,0) coordinate (C2pos)
    to[C, l_=$C$] ++(0,-2)
    (C2pos)
    to[short] ++(1.5,0)
    to[R, l_=$R$] ++(0,-2)
    to[short] ($(N2)+(0,-2)$)
    to[L] (N2)
    (C2pos)++(2,0)
    to[open, v^>=$v_{out}$] ++(0,-2);
    % ------------------------ Transformer lines
    \draw($(N1)!0.5!(N2)$)++(-0.05,-0.5)
    -- ++(0,-1) ++(0.1,0) -- ++(0,1)
    % again, here "red" alone fails 
    ($(N1)+(-0.15,-0.7)$) node[color=red, circ] {}
    ($(N2)+(+0.15,-1.3)$) node[circ] {}
    ;
\end{circuitikz}

输出

相关内容