6

Is it possible to make circuitikz draw all resistors red or all capacitors blue? I can make all bipoles thick, for example, but cant make all resistors red. I have to write the color explicitly. I cannot find a ctikzset command for this. This is an example. I want to get rid of the color=red for all resistors.

\documentclass{standalone}
\usepackage[american,cuteinductors]{circuitikz}
\usetikzlibrary{shapes,arrows,circuits,calc,babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}
\begin{tikzpicture}[transform shape, scale=1.0,thick]
\ctikzset{bipoles/thickness=2}
\ctikzset{label/align = smart}
\draw (0, 0) to [battery1, color=green, l=$\mathcal{E}$, invert] (0, 4) -- (4,4) to [R, l^=$R_1$, color=red] (2,2) to [R=$R_2$, color=red] (4, 0) -- (0, 0);
\draw (4, 4) to [R=$R_4$, color=red] (6, 2) to [R = $R_3$, color=red] (4, 0);
\draw (2, 2) to [C = $C$, color=blue] (6,2);
\end{tikzpicture}  
\end{document}

Thanks in advance. Edit: Making the code compilable.

  • If you complete your code so that it is compileable without further manual changes, then it will be easier to help. Right now it's not compileable. – Dr. Manuel Kuehner Mar 28 '17 at 5:17
  • @Dr.ManuelKuehner Yes, you can set the height and width using those flags, but not the color. I have not found yet how to do that and after checking the circuitikz code (I am not a Latex expert so I could have missed it) I cannot find any clue on how to set the color, not the dimensions. That is why I am asking here. – iluvatar Mar 28 '17 at 5:23
10

You can use \tikzset{R/.append style={color=red}} (see pgfkeys documentation page 888):

\documentclass{standalone}
\usepackage[american,cuteinductors]{circuitikz}
\usetikzlibrary{shapes,arrows,circuits,calc,babel}
\usepackage{pgfplots}

\tikzset{
    R/.append style={color=red},
    C/.append style={color=blue},
    battery1/.append style={color=green},
}

\begin{document}
\begin{tikzpicture}[transform shape, scale=1.0,thick]
\ctikzset{bipoles/thickness=2}
\ctikzset{label/align = smart}
\draw (0, 0) to [battery1, l=$\mathcal{E}$] (0, 4) -- (4,4) to [R, l^=$R_1$] (2,2) to [R=$R_2$] (4, 0) -- (0, 0);
\draw (4, 4) to [R=$R_4$] (6, 2) to [R = $R_3$] (4, 0);
\draw (2, 2) to [C = $C$] (6,2);
\end{tikzpicture}  
\end{document}

screenshot

Edit: If you want to change the color of the labels, too, you can use the /tikz/text key:

\tikzset{
    R/.append style={color=red, /tikz/text=red},
    C/.append style={color=blue, /tikz/text=blue},
    battery1/.append style={color=green, /tikz/text=green},
}

screenshot of the edit

  • Thanks a lot! This is exactly what I was looking for. Now I have to fiz those labels :) – iluvatar Mar 28 '17 at 12:10
  • That is useful. Although I mean the positions. Thanks again. – iluvatar Mar 30 '17 at 18:28
  • @iluvatar have you figured out how that works? According to the circuitikz documentation (page 34) it should be possible to specify whether the label shall be placed above or below with l^=$R_1$ or l_=$R_1$. However that does not seem to work on my system (version 0.3.0). – jakun Mar 31 '17 at 6:56
  • Hi @jakun, yes, that does not work either for me, and I am not sure if it is due to the fact that the labels are rotated ... At the end I leave them as shown. – iluvatar Apr 15 '17 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.