8

I'm new to circuitikz and fairly new to TikZ, and have a seemingly simple problem. The labels on my resistors are on opposite sides, for no reason that I can find.

output

\documentclass{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{tikzpicture}[node distance = 0.5cm, auto, font=\tiny, inner sep =0.8mm,american voltages]
    \ctikzset {label/align = straight }
    %PSU
    \draw[dashed](0.5,-3.5)rectangle(3.5,2.5);  
    \node at (2,2.7) (PSU_l){PSU};
    \draw (2,0) to[V=$V_{\mathrm{DS}}$,*-*] (2,2);
    \draw (2,-3) to[V=$V_{\mathrm{GS}}$,*-*] (2,-1);
    \draw (2,-1) to (4,-1) to (4,0) to (2,0);

    %Load resistors 
    \draw (2,2) to (4,2);
    \draw (4,2)to[R=$R_{\mathrm{L1}}$,*-*] (4,0); 
    \draw (2,-3) to (4,-3);
    \draw(4,-3)to[R=$R_{\mathrm{L2}}$,*-*] (4,-1); 
\end{tikzpicture}
\end{document}

I could presumably place the labels (semi-)manually (as I don't know how to place a node relative to a path I'd have to place them fully manually for now) but I feel sure there should be a way to say which side of the resistor (or other line) to put the label.

2
  • 2
    One is on a path going up the other going down
    – percusse
    Commented Mar 17, 2014 at 19:55
  • [continuing percusse's comment] hence you have to play with l^ or l_ accordingly. Commented Mar 17, 2014 at 20:03

2 Answers 2

9

As has been mentioned in the comments, you get a different placement because different directions are used by the paths: the first component is on a path that goes downwards and the second one is on a path going upwards.

circuitikz uses the direction of the path to place the labels; by default, labels are placed to the right for paths going downwards and above for paths going from left to right; labels are placed to the left for paths going upwards and below for paths going right to left. The default placement location can be changed using the l^, l_ modifiers (see second code below).

To get a consistent result, you can simply draw your components using paths in the same direction, so for the second component, instead of

\draw(4,-3)to[R=$R_{\mathrm{L2}}$,*-*] (4,-1); 

you can use

\draw(4,-1)to[R=$R_{\mathrm{L2}}$,*-*] (4,-3); 

A complete example:

\documentclass{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{tikzpicture}[node distance = 0.5cm, auto, font=\tiny, inner sep =0.8mm,american voltages]
    \ctikzset {label/align = straight }
    %PSU
    \draw[dashed](0.5,-3.5)rectangle(3.5,2.5);  
    \node at (2,2.7) (PSU_l){PSU};
    \draw (2,0) to[V=$V_{\mathrm{DS}}$,*-*] (2,2);
    \draw (2,-3) to[V=$V_{\mathrm{GS}}$,*-*] (2,-1);
    \draw (2,-1) to (4,-1) to (4,0) to (2,0);

    %Load resistors 
    \draw (2,2) to (4,2);
    \draw (4,2)to[R=$R_{\mathrm{L1}}$,*-*] (4,0); 
    \draw (2,-3) to (4,-3);
    \draw(4,-1)to[R=$R_{\mathrm{L2}}$,*-*] (4,-3); 
\end{tikzpicture}
\end{document}

enter image description here

Another option is to draw your paths in any direction and then use the l^= or l_= syntax to place the labels at the appropriate location:

\documentclass{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{tikzpicture}[node distance = 0.5cm, auto, font=\tiny, inner sep =0.8mm,american voltages]
    \ctikzset {label/align = straight }
    %PSU
    \draw[dashed](0.5,-3.5)rectangle(3.5,2.5);  
    \node at (2,2.7) (PSU_l){PSU};
    \draw (2,0) to[V=$V_{\mathrm{DS}}$,*-*] (2,2);
    \draw (2,-3) to[V=$V_{\mathrm{GS}}$,*-*] (2,-1);
    \draw (2,-1) to (4,-1) to (4,0) to (2,0);

    %Load resistors 
    \draw (2,2) to (4,2);
    \draw (4,2)to[R=$R_{\mathrm{L1}}$,*-*] (4,0); 
    \draw (2,-3) to (4,-3);
    \draw(4,-3)to[R,l_=$R_{\mathrm{L2}}$,*-*] (4,-1); 
\end{tikzpicture}
\end{document}
1
  • Embarrassingly simple when you know the answer - somehow I'd missed the example in the manual that would have suggested it.
    – Chris H
    Commented Mar 18, 2014 at 9:19
1

A PSTricks solution:

\documentclass{article}

\usepackage{pst-circ}

\begin{document}

\begin{pspicture}(7.25,10.4)
  \pnodes{P}(0,0)(0,0)(0,10)(5,10)(2.5,1)(2.5,4.5)(6,4.5)(6,1)(2.5,5.5)(2.5,9)(6,9)(6,5.5)
  \psframe[linestyle = dashed](P1)(P3)
  \pcline[linestyle = none, offset = 9pt](P2)(P3)
  \ncput{\textsc{psu}}
 \psset{arrows = *-*, dipolestyle = zigzag, labelInside = 2, labeloffset = 1}
  \Ucc(P4)(P5){$V_{\textsc{gs}}$}
  \wire(P5)(P6)
  \resistor(P6)(P7){$R_{\textsc{l}2}$}
  \wire(P7)(P4)
  \Ucc(P8)(P9){$V_{\textsc{ds}}$}
  \wire(P9)(P10)
  \resistor(P10)(P11){$R_{\textsc{l}1}$}
  \wire(P11)(P8)
\end{pspicture}

\end{document}

output

You must log in to answer this question.

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