3

In Shifting the +- voltage signs in circuitikz answer, they used "/tikz/circuitikz/voltage/distance from node" to set the distance that the +/- signs are away from the component (or well, node), and when I use that exact code, it works as shown, but I can't figure out why my code it doesn't seem to work. Am I using ctikzset incorrectly?

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

\begin{document}
\begin{circuitikz}
\ctikzset{/tikz/circuitikz/voltage/distance from node=0.3cm}
\draw
    (0,0) to [generic, v<=40<\volt>] (0,3);
\end{circuitikz}

\begin{circuitikz}
\ctikzset{/tikz/circuitikz/voltage/distance from node=1cm}
\draw
    (0,0) to [generic, v<=40<\volt>] (0,3);
\end{circuitikz}

\end{document}

Different distance from node, but same figure

1
  • 4
    Use \ctikzset{bipoles/generic/voltage/distance from node=0.3cm}. – user31034 Aug 29 '20 at 18:51
4

I add the MWE with the suggestion of the very nice user @ferahfeza.

\documentclass[12pt]{standalone}
\usepackage[siunitx, american]{circuitikz}

\begin{document}
\begin{circuitikz}
\ctikzset{bipoles/generic/voltage/distance from node=0.6cm}
\draw
    (0,0) to [generic, v<=40<\volt>] (0,3);
\end{circuitikz}

\begin{circuitikz}
\ctikzset{/tikz/circuitikz/voltage/distance from node=1cm}
\draw
    (0,0) to [generic, v<=40<\volt>] (0,3);
\end{circuitikz}

\end{document}

enter image description here

3

I will add an answer here because although the given answer works, it seems to me that it has a couple of misunderstandings.

First of all --- \ctikzset{key} is equivalent to (roughly) \tikzset{/tikz/circuitikz/key}, so the usage of that command is somehow redundant above.

Look at the following example:

\documentclass[12pt]{standalone}
\usepackage[EFvoltages, siunitx, american]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw (-2,0) to [generic, v<=1<\volt>, d-d] ++(0,3);
\ctikzset{voltage/distance from node=1cm}
\draw (0,0) to [generic, v<=2<\volt>, d-d] ++(0,3);
\ctikzset{bipoles/generic/voltage/distance from node=.3cm}
\draw (2,0) to [generic, v<=3<\volt>, d-d] ++(0,3);
\ctikzset{bipoles/generic/voltage/distance from node=1cm}
\draw (4,0) to [generic, v<=4<\volt>, d-d] ++(0,3);
\end{circuitikz}
\end{document}

The output it the following:

enter image description here

As you can see, it seems that the first \ctikzset is doing nothing --- the components with 1V and 2V have the same position of + and - (in reality, it is wreaking havoc, read on). This is because the voltage/distance from node key is the default one, which in the case of generic is overridden by the component-specific distance[*] bipoles/generic/voltage/distance from node which is set to 0.4. The meaning is explained here --- this is a proportional distance from the node to the component:

enter image description here

...as you can see, now the command works as expected. Notice that if you use absolute values for the distance from node you are on yourself if the lead is smaller...

Technical note: the argument of distance from node is really used in a TikZ calc expression like: ($(node)!argument!(start of the component)$)

Why is wreaking havoc the first command: because now it has set the distance to 1cm for all the components minus the special ones below...

There will be a documentation patch soon: https://github.com/circuitikz/circuitikz/pull/438


  • this happens for generic, ageneric, memristor, fullgeneric and open. I'll document it in the next version of the manual.
1
  • Excellent explanation. – Sebastiano Aug 31 '20 at 11:38

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.