4

I have written a custom circuitikz style file but it doesn't apply the option line width specified in the tikz-level settings block in line 7.

My style file ctikzstyle-mystyle.tex with the name mystyle:

% Do not use LaTeX commands if you want it to be compatible with ConTeXt!
% Do not add spurious spaces!
%
\tikzset{mystyle circuit style/.style={%
% generic tikz-level settings
american,%
line width=1pt,% PROBLEM HERE
%
\circuitikzbasekey/.cd,%
% circutikz-level settings
%
% RESISTORS
resistors/scale=0.7,
resistors/thickness=1.0,
%
% CAPACITORS
capacitors/scale=0.7,
capacitors/thickness=1.0,
bipoles/capacitor/width/.initial=.13,
%
% GROUND
grounds/scale=1.0,
grounds/thickness=1.0,
%
% SOURCES (the round ones)
sources/scale=0.7,
sources/thickness=1.0,
%
% OTHER OPTIONS
bipoles/thickness=1,
nodes width/.initial=.03,
%
},% end .style
}% end \tikzset
\endinput

Here an example circuit:

\documentclass[border = 1cm, tikz]{standalone}
\usepackage{circuitikz}
\ctikzsetstyle{mystyle}
\begin{document}
%
\begin{tikzpicture}
    \draw (0,0) to[short, o-]  ++(1,  0)
                to[R]          ++(0, -2)
                to[short]      ++(1,  0) coordinate(e)
                to[short, *-o] ++(0, -1);
\draw(4,0) to[short, o-] ++(-1,  0)
           to[isource]   ++( 0, -2)
           to[short] (e);

\end{tikzpicture} % \end{document}

Both files, the example and the style file are in the same folder.

In principle the style file works but the line width doesn't change as expected. It has still the default value of 0.4pt instead of 1pt.

molybdän
  • 105
  • Does https://tex.stackexchange.com/questions/338608/change-default-line-width-in-circuitikz help? – John Kormylo Feb 24 '21 at 14:01
  • I think the problem is that line width is reset at the start of any picture. Maybe this https://tex.stackexchange.com/a/389169/38080 helps? – Rmano Feb 24 '21 at 14:11
  • @JohnKormylo that will set the line width of the components, not the standard used by, for example, -- in diagrams. – Rmano Feb 24 '21 at 14:15
  • @Rmano i just want to omit the optional argument of the circuitikz environment \begin{tikzpicture}[line width=1pt] out of laziness and i don't want to modify the line width in other tikzpictures. The solution in your link doesn't seem to save me from typing. – molybdän Feb 24 '21 at 15:53
  • Unfortunately line width is globally set --- so the other option you have is to say \begin{tikzpicture}[mystyle circuit style] ... with your original style --- it should work. – Rmano Feb 24 '21 at 16:06
  • @Rmano i will use your last suggestion. That way, one file contains the style definition and that is what I want.Thank you! – molybdän Feb 24 '21 at 17:28

1 Answers1

3

The minimum change (from Change all line width proportionally) would be to change your "PROBLEM HERE" line with:

every picture/.append style={line width=1pt},

enter image description here

but notice that this will apply to all tikzpicture in the document. In the answer to the aforementioned linked question the is a more nuanced version.

If you do not want to apply the new line width to all tikzpictures (and remember that circuitikz is just an alias for this), you can use your original style file but apply it explicitly to the circuits --- you can also give it a shortname:

\documentclass[border = 1cm, tikz]{standalone}
\usepackage{circuitikz}
\ctikzloadstyle{mystyle} % maybe just load it, without setting as default
% shortcut
\tikzset{mystyle/.style={mystyle circuit style}}
\begin{document}
%
\begin{tikzpicture}[mystyle]
    \draw (0,0) to[short, o-]  ++(1,  0)
                to[R]          ++(0, -2)
                to[short]      ++(1,  0) coordinate(e)
                to[short, *-o] ++(0, -1);
\draw(4,0) to[short, o-] ++(-1,  0)
           to[isource]   ++( 0, -2)
           to[short] (e);

\end{tikzpicture} % \end{document}

...and the result is the same.

Rmano
  • 40,848
  • 3
  • 64
  • 125