目前,只有电流和电压的名称是红色/蓝色。我还希望它们的箭头也是红色/蓝色。如何实现?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{circuitikz}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt
\usetikzlibrary{quotes, angles, calc, babel}
\ctikzset{bipoles/thickness=0.8}
\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}
\ctikzset{inductors/scale=0.8, inductor=american}
\tikzstyle{every path}=[line width=0.8pt,line cap=round,line join=round]
\usepackage[backend=biber, sorting=none]{biblatex}
\begin{document}
\begin{circuitikz}[american, straight voltages, scale=0.84]
\draw (0,0)
to[battery, l={\textcolor{blue}{$U_e$}}] (0,4) -- (1.5,4)
to[C, l=$C_1$, i={\textcolor{red}{$I_{C_1}$}}, -*] (1.5,0) -- (0,0) -- (3.5,0)
to[switch, l=$S_2$] (3.5,1.5) -- (3.5,2.5) node[circ]{}
to[switch, l=$S_1$, -*] (3.5,4) -- (1.5,4) node[circ]{} -- (5.5,4)
to[C, l=$C_3$, v={\textcolor{blue}{$\frac{U_e}{2}$}}] (5.5,2.5) -- (5.5,1.5) node[circ]{}
to[C, l=$C_4$, v={\textcolor{blue}{$\frac{U_e}{2}$}}] (5.5,0) -- (3.5,0) node[circ]{};
\draw (8.25,4) to[L , v={\textcolor{blue}{$U_s$}}] (8.25,2);
\draw (8.25,1.5) to[L, v={\textcolor{blue}{$U_s$}}] (8.25,-0.5);
\draw (3.5,2.5) -- (7,2.5) to[L, v={\textcolor{blue}{$U_p$}}] (7,1.5) -- (5.5,1.5);
\draw (7.45,3.5) -- (7.45,0.5);
\draw (7.55,3.5) -- (7.55,0.5);
\draw (8.25,4) -- (11,4)
to[L, l=$L_1$, v={\textcolor{blue}{$U_{L_1}$}}] (14,4) -- (16.5,4) node[circ]{} -- (18,4) node[ocirc]{} -- (16.5,4)
to[C, l=$C_2$, i={\textcolor{red}{$I_{C_2}$}}, -*] (16.5,-1.5) -- (18,-1.5) node[ocirc]{} -- (13.5,-1.5) node[circ]{}
to[switch, l=$S_4$] (13.5,2) -- (8.25,2);
\draw(14,4)
node[flowarrow]{\textcolor{red}{$I_{L_1}$}};
\draw (13.5,-1) node[circ]{} -- (14.5,-1)
to[D-] (14.5,1) -- (13.5,1) node[circ]{};
\draw (13.5,-1.5) -- (10.5,-1.5)
to[switch, l=$S_3$] (10.5,1.5) -- (8.25,1.5);
\draw (10.5,-1) node[circ]{} -- (11.5,-1)
to[D-] (11.5,1) -- (10.5,1) node[circ]{};
\draw (8.25,-0.5) -- (9,-0.5) -- (9,4) node[circ]{};
\draw [<->, color=blue] (18,3.8) -- (18,-1.3) node[midway, fill=white]{$U_a$};
\end{circuitikz}
\end{document}
编辑:
在...的帮助下https://texdoc.org/serve/circuitikz/0#subsection.5.8我设法给电压着色,但没能给电流着色。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{circuitikz}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt
\usetikzlibrary{quotes, angles, calc, babel}
\ctikzset{bipoles/thickness=0.8}
\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}
\ctikzset{inductors/scale=0.8, inductor=american}
\tikzstyle{every path}=[line width=0.8pt,line cap=round,line join=round]
\usepackage[backend=biber, sorting=none]{biblatex}
\NewDocumentCommand{\fixedvlen}{O{0.44cm} m m O{}}{% [semilength]{node}{label}[extra options]
% get the center of the standard arrow
\coordinate (#2-Vcenter) at ($(#2-Vfrom)!0.5!(#2-Vto)$);
% draw an arrow of a fixed size around that center and on the same line
\draw[-Triangle, #4] ($(#2-Vcenter)!#1!(#2-Vfrom)$) -- ($(#2-Vcenter)!#1!(#2-Vto)$);
% position the label as in the normal voltages
\node[anchor=\ctikzgetanchor{#2}{Vlab}, #4] at (#2-Vlab) {#3};
}
\begin{document}
\begin{circuitikz}[american, straight voltages, scale=0.84]
\draw (0,0)
to[battery, l={\textcolor{blue}{$U_e$}}] (0,4) -- (1.5,4)
to[C, l=$C_1$, i={\textcolor{red}{$I_{C_1}$}}, -*] (1.5,0) -- (0,0) -- (3.5,0)
to[switch, l=$S_2$] (3.5,1.5) -- (3.5,2.5) node[circ]{}
to[switch, l=$S_1$, -*] (3.5,4) -- (1.5,4) node[circ]{} -- (5.5,4)
to[C, l=$C_3$, v=, name=vC3] (5.5,2.5) -- (5.5,1.5) node[circ]{}
to[C, l=$C_4$, v=, name=vC4] (5.5,0) -- (3.5,0) node[circ]{};
\draw (8.4,4) to[L , v=, name=vS2] (8.4,2);
\draw (8.4,1.5) to[L, v=, name=vS] (8.4,-0.5);
\draw (3.5,2.5) -- (7,2.5) to[L, v=, name=vP] (7,1.5) -- (5.5,1.5);
\draw (7.45,3.5) -- (7.45,0.5);
\draw (7.55,3.5) -- (7.55,0.5);
\draw (8.4,4) -- (11.15,4)
to[L, l=$L_1$, v=, name=vL1] (14.15,4) -- (16.65,4) node[circ]{} -- (18.15,4) node[ocirc]{} -- (16.65,4)
to[C, l=$C_2$, i={\textcolor{red}{$I_{C_2}$}}, -*] (16.65,-1.5) -- (18.15,-1.5) node[ocirc]{} -- (13.65,-1.5) node[circ]{}
to[switch, l=$S_4$] (13.65,2) -- (8.4,2);
\draw(14.15,4)
node[flowarrow]{\textcolor{red}{$I_{L_1}$}};
\draw (13.65,-1) node[circ]{} -- (14.65,-1)
to[D-] (14.65,1) -- (13.65,1) node[circ]{};
\draw (13.65,-1.5) -- (10.65,-1.5)
to[switch, l=$S_3$] (10.65,1.5) -- (8.4,1.5);
\draw (10.65,-1) node[circ]{} -- (11.65,-1)
to[D-] (11.65,1) -- (10.65,1) node[circ]{};
\draw (8.4,-0.5) -- (9.15,-0.5) -- (9.15,4) node[circ]{};
\draw [<->, color=blue] (18.15,3.8) -- (18.15,-1.3) node[midway, fill=white]{$U_a$};
\fixedvlen{vL1}{$U_{L_1}$}[blue]
\fixedvlen{vS}{$U_s$}[blue]
\fixedvlen{vS2}{$U_s$}[blue]
\fixedvlen{vP}{$U_p$}[blue]
\fixedvlen{vC3}{$\frac{U_e}{2}$}[blue]
\fixedvlen{vC4}{$\frac{U_e}{2}$}[blue]
\end{circuitikz}
\end{document}
答案1
您应该使用手册中提供的用于蓝色箭头的相同技术,并根据电流对其进行调整。您已在图表中指定了所有标签第 5.8.1 节。
A真实的 最小下面是一个示例,还展示了如何以相同的样式手动添加电压电流。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{circuitikz}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt
% so it's 0.75pt or 0.9pt???
\tikzstyle{every path}=[line width=0.8pt,line cap=round,line join=round]
\NewDocumentCommand{\fixedvlen}{O{0.44cm} m m O{}}{% [semilength]{node}{label}[extra options]
% get the center of the standard arrow
\coordinate (#2-Vcenter) at ($(#2-Vfrom)!0.5!(#2-Vto)$);
% draw an arrow of a fixed size around that center and on the same line
\draw[-Triangle, #4] ($(#2-Vcenter)!#1!(#2-Vfrom)$) -- ($(#2-Vcenter)!#1!(#2-Vto)$);
% position the label as in the normal voltages
\node[anchor=\ctikzgetanchor{#2}{Vlab}, #4] at (#2-Vlab) {#3};
}
\NewDocumentCommand{\redcurrent}{mm}{% node, label
% position the circuitikz arrow shape in the normal position and direction
% but color it red
\node[currarrow, color=red, rotate=\ctikzgetdirection{#1}] at (#1-Ipos){};
% ditto for the label
\node[red,anchor=\ctikzgetanchor{#1}{Ilab}] at (#1-Ipos) {#2};
}
\begin{document}
\begin{circuitikz}[american, straight voltages, scale=0.84]
\draw (0,0)
to[C, l=$C_1$, i=, -*, name=ic1, v=] (3.5,0);
% this an independent, manually positioned red current arrow
\draw(0,1) node[currarrow, color=red]{} node[above,red] {$I_{L_1}$};
\draw[blue, -Triangle] (4,1.5) -- (4,-0.5) node[midway, right]{$U_r$};
\fixedvlen{ic1}{$U_{L_1}$}[blue]
\redcurrent{ic1}{$I_{C_1}$}
\end{circuitikz}
\end{document}
请注意:
- 线宽的设置有冲突;
\usepackage[utf8]{inputenc}
已经违约好几年了,但是你可能想要\usepackage[T1]{fontenc}
;- 您正在使用“类”参数(可以)和内部参数(很危险,它们将来可能会发生变化)来设置组件的样式;
scale=0.84
变化只有坐标,不是节点大小也不是字体;你可能是指scale=0.84, transform shape
那里;那将缩放除线宽之外的任何东西(或多或少)。