2

Currently, only the names of currents and voltages are red/blue. I'd also like their arrows to be red/blue. How can this be done?

\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}

EDIT:

With the help of https://texdoc.org/serve/circuitikz/0#subsection.5.8 i managed to color the voltages, but not the currents.

\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
  • 1
    Do you want to make a separate arrow adjacent the current symbols and color that red? or do you want to color the circuit path segment adjacent the current symbols red?
    – SolidMark
    Jun 24, 2021 at 8:51

1 Answer 1

1

You should use the same techniques used for the blue arrows that you got from the manual and adapt them for the currents. You have all the labels specified in the diagrams in section 5.8.1.

A real minimal example follows, showing also how to manually add a current of a voltage with the same style.

enter image description here

\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}

Notice that:

  1. you have conflicting setups for the line width;
  2. \usepackage[utf8]{inputenc} is default since a couple of years, but you probably want \usepackage[T1]{fontenc};
  3. You are styling components with both "class" parameters (ok) and internal parameters (dangerous, they can change in the future);
  4. scale=0.84 changes only the coordinates, not node sizes nor fonts; you probably meant scale=0.84, transform shape there; that will scale anything but the linewidths (more or less).
6
  • I have one more question. I'd like to draw an independent voltage arrow, like \draw [color=blue] (18.15,3.8) to[open, v=$U_a$] (18.15,-1.3); Unfortunately it doesn't have the same look like an arrow drawn with fixedvlen. What can i do for that?
    – Dede_
    Jun 25, 2021 at 7:30
  • Why not using the same technique? \draw (18.14,3.8) to[open, v, name=myopen] (18.15,-1.3); \fixedvlen{myopen}{$U_a$}[blue] (but you should learn to use named and relative coordinates, your life will be much more simple). The other option is to mimic the arrow command that you put into the \fixedvlen macro.
    – Rmano
    Jun 25, 2021 at 7:58
  • In this case, the arrow shouldn't have the same length as the other ones. It should really be from (18.15,3.8) to (18.15,-1.3).
    – Dede_
    Jun 25, 2021 at 8:02
  • I added a bit with manually added arrows to the answer.
    – Rmano
    Jun 25, 2021 at 15:27
  • Okay, thank you. I have one more question. As my circuit is very close to right margin, i'd like to put my circuit in the center of the page. I tried \centering, but it did not work.
    – Dede_
    Jun 27, 2021 at 11:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .