6

Is it possible to get a labelname in circuitikz to be equal to the output from

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}[circuit ee IEC,every info/.style={font=\footnotesize},set resistor graphic=var resistor IEC graphic]
    \draw (0,0) to[resistor={info={$R_\text{L}=\SI{220}{\ohm}$}}] (2,0);
\end{tikzpicture}
\end{document}

As far I've understood there's no "info" property in circuitikz, so I can't figure out how to do the same with that package. E.g., using something like

\draw (0,0) to[R=$R_1=\SI{2}{\ohm}$] (2,0)

results in an error in circuitikz.

If possible, I'd prefer to use circuitikz over the circuits.ee.IEC library as I like the symbols in circuitikz more.

Best regards, dm

Edit:

circuitikz example that's not working:

\documentclass{article}
\usepackage{tikz}
\usepackage[siunitx,european,americanresistors]{circuitikz}
\begin{document}
\begin{tikzpicture}[american currents]
    \draw (0,0) to[R=$R_1=\SI{2}{\ohm}$] (2,0);
\end{tikzpicture}
\end{document}
11
  • Does it work if you don't use \SI? I've had issues with siunitx and pgfplots, so it could be that it clashes with TikZ.
    – qubyte
    Dec 21, 2011 at 12:36
  • No, unfortunately. I get the following error: "! Extra }, or forgotten $.\@let@token ...rc@temp ) {\pgf@circ@finallabel {}}"
    – blubbafett
    Dec 21, 2011 at 12:40
  • Your code compiles fine for me (looks nice too). I'm on an up to date TeXLive 2011 though. What are you using?
    – qubyte
    Dec 21, 2011 at 12:49
  • You compile fine when you use circuitikz and a command like i.e. \draw (0,0) to[R=$R_1=\SI{2}{\ohm}$] (2,0) ? I use TexLive 2011, which I updated about two weeks ago. But I'll run an update now and see if it works after the update. Edit: tried to compile now after updating, still the same error when using circuitikz.
    – blubbafett
    Dec 21, 2011 at 12:52
  • Oh, I'm sorry, I've misread the question! If possible, could you provide a nearly complete example with circuitikz that you'd like modified?
    – qubyte
    Dec 21, 2011 at 12:53

3 Answers 3

9

Putting the label in a \mbox seems to do the trick. Try the following version:

\documentclass{standalone}
\usepackage{tikz}
\usepackage[siunitx,european,americanresistors]{circuitikz}
\begin{document}
\begin{tikzpicture}[american currents]
    \draw (0,0) to[R,label=\mbox{$R_1=\SI{2}{\ohm}$}] (2,0);
\end{tikzpicture}
\end{document}

enter image description here

1
  • You're most welcome!
    – qubyte
    Dec 21, 2011 at 13:09
7

The problem is that TikZ thinks a = identifies a new option. Like in

(0,0) node[R,l=test=yes]

it is assumed that l=tes and t=yes (or something like this... At least it breaks!)

Inside a math environment, you can escape the "equals" by {=}:

(0,0) to[R,l=$R_g{=}\SI{10}{\ohm}$] ++(2,0);
2
  • 4
    Actually, =yes is just discarded. With your solution, the = has wrong spacing. It would be better to do to[R,label=${R_1=\SI{2}{\ohm}}$]. (At the most outer place, it would need eight braces because of how PGFkeys strips one pair away on the way to the actual key that deals with the labeling. I blame circuitikz for not inserting { } again.) Nov 12, 2013 at 16:28
  • @Qrrbrbirlbel You’re right, and this has since been fixed, see my new answer. ;)
    – Archange
    Oct 16, 2021 at 14:10
2

Starting with circuitikz 1.3, this issue has been fixed in the sense that you can now protect the content with outer braces just like standard TikZ:

\documentclass{standalone}
\usepackage[siunitx,european,americanresistors]{circuitikz}
\begin{document}
\begin{tikzpicture}[american currents]
    \draw (0,0) to[R={$R_1=\SI{2}{\ohm}$}] (2,0);
\end{tikzpicture}
\end{document}

This was fixed by @Rmano in PR#484.

You must log in to answer this question.

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