Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How could I go about writing the label R1, with the resistance of 560 ohms underneath it using Circuitikz? Ideally, I want a newline in the resistor label.

\begin{circuitikz}
%\draw[style=help lines] (-8,-8) grid (8,8);
\draw
(0,0) node[npn,rotate=90] (darl) {} node[above] {$Q1$}
(0,-3)      node[npn,xscale=-1] (npn) {} node[left] {$Q2$}
(darl.B)    to[short,-*,i<^=\SI{37.2}{\micro\ampere}] ++(0,-0.65) node (base) {}
            to[short,i>^=\SI{5.67}{\milli\ampere}] (npn.C)

(darl.E)    to[short,-*,i=\SI{518}{\milli\ampere}] ++(1.23,0) node (zen) {}
            to[short,-*] ++(2,0) node (div) {}
            to[short,-o] ++(1.5,0)  node (out1) {}
            to[short] ++(1,0)
            to[vR,i>^=\SI{500}{\milli\ampere},l=$R_L$] ++(0,-6)
            to[short,-o] ++(-1,0) node (out2) {}
            to[short,-*] ++(-1.5,0)
            to[short,-*] ++(-4,0)
            to[short] ++(-3.5,0)
            to[V,l=\SI{18}{\volt}] ++(0,6)

(zen)       to[R,l=\SI{1.2}{\kilo\ohm},i>^=\SI{5.41}{\milli\ampere}] ++(0,-3)
            |- (npn.E)

(0,-6)      to[zD,-*,v_>=\SI{6.2}{\volt},i^<=\SI{12.7}{\milli\ampere}] (npn.E)
(div)       to[R,-*,l=$\SI{470}{\ohm}$,i>^=\SI{12.3}{\milli\ampere}] ++(0,-3) node (fb) {}
            to[R,l=$\SI{560}{\ohm}$,v_=\SI{6.90}{\volt}] ++(0,-3)

(npn.B)     to[short] (fb)

(darl.C)    to[short,-*] ++(-1,0) node (Rbe) {}
            to[short] ++(-0.235,0)
            to[short] ++(-1.5,0)

(Rbe)       to[short,i_=\SI{5.71}{\milli\ampere}] ++(0,-1.5)
            to[R,l_=\SI{680}{\ohm}] ++(1.76,0)

(6.5,0)     to[short,*-o] ++(1,0) node[right] {$\SI{12.7}{\volt}$}
;
\end{circuitikz}

ShuntRegulator

share|improve this question
    
This should work as always and as explained in Manual/automatic line breaks and text alignment in TikZ nodes. It is just a matter of how to use align=left for the node that is used by circuitikz. A rather unpleasant way would be to use {[every node/.append style={align=left}] to[R,l=$R_1$\\$\SI{560}{\ohm}$,v_=\SI{6.90}{\volt}] ++(0,-3) } as it also changes the alignment of 6.90 V. –  Qrrbrbirlbel Oct 4 '13 at 2:57
    
Okay, though I'm not sure how this works given that the resistor is not a node, it's to[R...]. Could you perhaps give a code sample? Where does align=left go? –  user968243 Oct 4 '13 at 3:03
1  
Have you seen the linked question? It explains in great detail what align=left does. It basically allows you to use \\ for a line-break. Other options include the text width key (TikZ) or the use of a tabular (this would avoid other nodes using the same option). And yes, the text is indeed a node (the resistor is, too). — Of course, you can also use varwidth; but I’d prefer that circuitikz would offer better ways to change certain elements (i.e. styles) and/or allows us to use something like l={[<option>] Text}. –  Qrrbrbirlbel Oct 4 '13 at 3:12
    
Okay, this really does seems rather excessive... Curiously, do you know any alternative to Circuitikz? I'm actually finding it quite frustrating at times and slow. –  user968243 Oct 4 '13 at 3:24
    
You can use l=\parbox{5cm}{R1\\$\SI{560}{\ohm}$}. See tex.stackexchange.com/questions/127112/… about labeling both sides. –  John Kormylo Oct 4 '13 at 3:35

3 Answers 3

up vote 2 down vote accepted

You can label few things by yourselves:

(div)       to[R,-*,l=$\SI{470}{\ohm}$,i>^=\SI{12.3}{\milli\ampere}] ++(0,-3) node (fb) {}
            to[R,v_=\SI{6.90}{\volt}] node[midway,right=1.3em,align=left] {R2\\$\SI{560}{\ohm}$} ++(0,-3)

Full code:

\documentclass{article}
\usepackage{circuitikz}
\usepackage{siunitx}
\begin{document}
  \begin{circuitikz}
%\draw[style=help lines] (-8,-8) grid (8,8);
\draw
(0,0) node[npn,rotate=90] (darl) {} node[above] {$Q1$}
(0,-3)      node[npn,xscale=-1] (npn) {} node[left] {$Q2$}
(darl.B)    to[short,-*,i<^=\SI{37.2}{\micro\ampere}] ++(0,-0.65) node (base) {}
            to[short,i>^=\SI{5.67}{\milli\ampere}] (npn.C)

(darl.E)    to[short,-*,i=\SI{518}{\milli\ampere}] ++(1.23,0) node (zen) {}
            to[short,-*] ++(2,0) node (div) {}
            to[short,-o] ++(1.5,0)  node (out1) {}
            to[short] ++(1,0)
            to[vR,i>^=\SI{500}{\milli\ampere},l=$R_L$] ++(0,-6)
            to[short,-o] ++(-1,0) node (out2) {}
            to[short,-*] ++(-1.5,0)
            to[short,-*] ++(-4,0)
            to[short] ++(-3.5,0)
            to[V,l=\SI{18}{\volt}] ++(0,6)

(zen)       to[R,l=\SI{1.2}{\kilo\ohm},i>^=\SI{5.41}{\milli\ampere}] ++(0,-3)
            |- (npn.E)

(0,-6)      to[zD,-*,v_>=\SI{6.2}{\volt},i^<=\SI{12.7}{\milli\ampere}] (npn.E)
(div)       to[R,-*,l=$\SI{470}{\ohm}$,i>^=\SI{12.3}{\milli\ampere}] ++(0,-3) node (fb) {}
            to[R,v_=\SI{6.90}{\volt}] node[midway,right=1.3em,align=left] {R2\\$\SI{560}{\ohm}$} ++(0,-3)

(npn.B)     to[short] (fb)

(darl.C)    to[short,-*] ++(-1,0) node (Rbe) {}
            to[short] ++(-0.235,0)
            to[short] ++(-1.5,0)

(Rbe)       to[short,i_=\SI{5.71}{\milli\ampere}] ++(0,-1.5)
            to[R,l_=\SI{680}{\ohm}] ++(1.76,0)

(6.5,0)     to[short,*-o] ++(1,0) node[right] {$\SI{12.7}{\volt}$}
;
\end{circuitikz}
\end{document}

enter image description here

share|improve this answer
    
Thanks. Definitely seems rather over-the-top the length that one must go to in order to achieve this! –  user968243 Oct 4 '13 at 5:05

Here a node with label option xshift=xx yshift=xx is used to add the label R1. Also the 560 ohm is wrapped in raisebox to move up and down for alignment.

To save space I only post the line 28 that needs to be changed/appended. (The rest remains same)

(div) to[R,-*,l=$\SI{470}{\ohm}$,i>^=\SI{12.3}{\milli\ampere}] ++(0,-3) node   (fb) {} to[R,l=\raisebox{-1cm}{$\SI{560}{\ohm}$},v_=\SI{6.90}{\volt}] 
node[label= {[xshift=1cm,yshift=1ex]above:R1}]{} ++(0,-3)

And this is the result

enter image description here

share|improve this answer

With

\makeatletter
\expandafter\let\csname pgfk@\circuitikzbasekey/@loriginal/.@cmd\expandafter\endcsname\csname pgfk@\circuitikzbasekey/l/.@cmd\endcsname
\ctikzset{l/.code={%
  \pgfutil@ifnextchar[\pgf@circ@handleOPT{\pgf@circ@handleOPT[]}#1\pgf@stop}}
\def\pgf@circ@handleOPT[#1]#2\pgf@stop{%
  \def\pgf@circ@options{#1}%
  \ctikzset{@loriginal={#2}}}
\usepackage{etoolbox}
\patchcmd\pgf@circ@drawreglabel{]}{,style/.expand once=\pgf@circ@options]}{}{}
\makeatother

in the preamble, you can do

to[R,
   l={[align=left]$R_1$\\$\SI{560}{\ohm}$},
   v_=\SI{6.90}{\volt}
  ] ++(0,-3)

for every node separately.

Of course, you might define something like al/.style={align=left} to make the stuff shorter:

   l={[al]$R_1$\\\$SI{…}{…}$}

or even al/.style 2 args={l={[align=left]#1\\#2}} that is to be used as

   al={$R_1$}{$\SI{…}{…}$}

in the to path operator options.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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