4

I have coded the following circuit:

\documentclass{article}
\usepackage[american]{circuitikz}
\begin{document}

\begin{circuitikz}
\draw
(0,4) to [C,v^=\(v_c\),*-*] (0,1)
      to [short] (0,0)
      to [ospst=\mbox{t=0s}] (6,0)
      to [battery,v_=45V] (6,5)
      to [short] (5,5)
      to [open,*-*] (3,5)
      to [R=\parbox{1cm}{\(R_3\\5.6k\Omega\)}] (0,5)
      to [short] (0,4)
      to [short] (-6,4)
      to [C,l_=\parbox{1cm}{\(C_1\\4.7\mu F\)}] (-6,1)
      to [short] (0,1)
(-3,4)to [R,l_=\parbox{1cm}{\(R_4\\10k\Omega\)},*-*] (-3,1)
(3,6) to [short] (3,4)
      to [R,l_=\parbox{1cm}{\(R_2\\39k\Omega\)}] (5,4)
      to [short] (5,6)
      to [R,l=\parbox{1cm}{\(R_1\\47k\Omega\)}] (3,6)
;
\end{circuitikz}

\end{document}

Which, when rendered, looks like this:

Circuitikz Schematic

Questions:

  1. How can component reference designators (R1) and values (47kΩ) be horizontally aligned (centered) with each other and the component? Using \centering, generates a compile error since the contents of the \parbox is an equation which is required for subscripting and Greek letters.
  2. When labels are added (see below) to the capacitor and battery, the voltages get skewed so that they are overlapping the components. How can this be resolved?

Modified code showing added labels (see first and fourth lines after \draw command):

\documentclass{article}
\usepackage[american]{circuitikz}
\begin{document}

\begin{circuitikz}
\draw
(0,4) to [C,l_=\parbox{1cm}{\(C_2\\2.2\mu F\)},v^=\(v_c\),*-*] (0,1)
      to [short] (0,0)
      to [ospst=\mbox{t=0s}] (6,0)
      to [battery,l=E,v_=45V] (6,5)
      to [short] (5,5)
      to [open,*-*] (3,5)
      to [R=\parbox{1cm}{\(R_3\\5.6k\Omega\)}] (0,5)
      to [short] (0,4)
      to [short] (-6,4)
      to [C,l_=\parbox{1cm}{\(C_1\\4.7\mu F\)}] (-6,1)
      to [short] (0,1)
(-3,4)to [R,l_=\parbox{1cm}{\(R_4\\10k\Omega\)},*-*] (-3,1)
(3,6) to [short] (3,4)
      to [R,l_=\parbox{1cm}{\(R_2\\39k\Omega\)}] (5,4)
      to [short] (5,6)
      to [R,l=\parbox{1cm}{\(R_1\\47k\Omega\)}] (3,6)
;
\end{circuitikz}

\end{document}

Resulting compilation:

circuitikz schematic with labels added

2

Remarks

Just use \centering inside of your parboxes. Also, I got an error ! LaTeX Error: There's no line here to end. This is due to the linebreaks being inside inline math mode.

Implementation

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage[american]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw
(0,4) to [C,l_=\parbox{1cm}{\centering\(C_2\)\\\(2.2\mu F\)},v^=\(v_c\),*-*] (0,1)
      to [short] (0,0)
      to [ospst=\mbox{t=0s}] (6,0)
      to [battery,l=E,v_=45V] (6,5)
      to [short] (5,5)
      to [open,*-*] (3,5)
      to [R=\parbox{1cm}{\centering\(R_3\)\\\(5.6k\Omega\)}] (0,5)
      to [short] (0,4)
      to [short] (-6,4)
      to [C,l_=\parbox{1cm}{\centering\(C_1\)\\\(4.7\mu F\)}] (-6,1)
      to [short] (0,1)
(-3,4)to [R,l_=\parbox{1cm}{\centering\(R_4\)\\\(10k\Omega\)},*-*] (-3,1)
(3,6) to [short] (3,4)
      to [R,l_=\parbox{1cm}{\centering\(R_2\)\\\(39k\Omega\)}] (5,4)
      to [short] (5,6)
      to [R,l=\parbox{1cm}{\centering\(R_1\)\\\(47k\Omega\)}] (3,6)
;
\end{circuitikz}
\end{document}

Output

enter image description here


To typeset units more easily, consider using the siunitx package.

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage[american,siunitx]{circuitikz}
\begin{document}
\begin{circuitikz}
\draw
(0,4) to [C,l_=\parbox{1cm}{\centering\(C_2\)\\\(\SI{2.2}{\micro\farad}\)},v^=\(v_c\),*-*] (0,1)
      to [short] (0,0)
      to [ospst=\mbox{$t = \SI{0}{\second}$}] (6,0)
      to [battery,l=$E$,v_=\SI{45}{\volt}] (6,5)
      to [short] (5,5)
      to [open,*-*] (3,5)
      to [R=\parbox{1cm}{\centering\(R_3\)\\\(\SI{5.6}{\kilo\ohm}\)}] (0,5)
      to [short] (0,4)
      to [short] (-6,4)
      to [C,l_=\parbox{1cm}{\centering\(C_1\)\\\(\SI{4.7}{\micro\farad}\)}] (-6,1)
      to [short] (0,1)
(-3,4)to [R,l_=\parbox{1cm}{\centering\(R_4\)\\\(\SI{10}{\kilo\ohm}\)},*-*] (-3,1)
(3,6) to [short] (3,4)
      to [R,l_=\parbox{1cm}{\centering\(R_2\)\\\(\SI{39}{\kilo\ohm}\)}] (5,4)
      to [short] (5,6)
      to [R,l=\parbox{1cm}{\centering\(R_1\)\\\(\SI{47}{\kilo\ohm}\)}] (3,6)
;
\end{circuitikz}
\end{document}

enter image description here

5
  • Thank-you, Henri Menke. I understand what I was doing wrong now with regards to the centering.
    – Ron Broad
    Jan 7 '14 at 17:38
  • The skewed voltage labels are still a problem for me. I'm going to try a different compiler.
    – Ron Broad
    Jan 7 '14 at 17:41
  • @RonBroad I don't see any obviously skewed labels in my output. Could you please elaborate? Jan 7 '14 at 19:30
  • I agree, your output is perfect, but mine still looks like the one I posted above with v_c and 45V crowded into the same space that the respective component occupy. The only thing I can figure is it might be a compiler issue. Which compiler are you using?
    – Ron Broad
    Jan 7 '14 at 23:45
  • By the way... For the sake of clarification, the centering part works great now. That was question #1. I'm just trying to resolve question #2 now. I think if I try a different compiler, like the one you're using, it will fix the problem.
    – Ron Broad
    Jan 7 '14 at 23:52

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.