3

I'm currently at 8th grade working on circuits and I'm taking notes with LaTeX and CircuiTikZ. The problem is that I have 2 circuits, but one is vertically bigger than the other, and so I don't know how to align those two circuits vertically.

Currently I have this code:

\begin{center}\begin{circuitikz}
\draw (0,0) -- (1,0) -- (1,1) to[R, l=$R_1$] (3,1) -- (3,0) -- (4,0);
\draw (1,0) -- (1,-1) to[R, l=$R_2$] (3,-1) -- (3,0);
\end{circuitikz}
$\ \ \Longleftrightarrow \ \ $
\begin{circuitikz}
\draw (0,0) to[R, l=$R$] (3,0);
\end{circuitikz}
\end{center}
$$R=\frac{1}{\frac{1}{R_1}+\frac{1}{R_2}} \Longleftrightarrow R=\left( \sum_n\frac{1}{R_n} \right)^{-1}$$

enter image description here

Then I tried adding a node at (4,0) and add the second circuit but I get this:

\begin{center}\begin{circuitikz}
\draw (0,0) -- (1,0) -- (1,1) to[R, l=$R_1$] (3,1) -- (3,0) -- (4,0);
\draw (1,0) -- (1,-1) to[R, l=$R_2$] (3,-1) -- (3,0);
\draw (4,0) node[right]{$\ \ \Longleftrightarrow \ \ $
\begin{circuitikz}
\draw (0,0) to[R, l=$R$] (3,0);
\end{circuitikz}};
\end{circuitikz}
\end{center}

enter image description here

Anyone knows how could I align the circuits?

1
  • 1
    $$ is not supported in LaTeX, use \[ and \] instead!, also instead of nesting two circuitikz environments (or putting them next to each other), simply draw both circuits in the same environment.
    – Skillmon
    Mar 5 at 10:49

2 Answers 2

5

One way to do this could look like this (I'd personally work more with relative placement than this, but this might do for OP).

The used scopes are not necessary for this, I only added them for semantic reasons and they could be dropped.

\documentclass[border=3.14,preview]{standalone}

\usepackage{circuitikz}

\begin{document}
\begin{center}
  \begin{circuitikz}
    \begin{scope} % not really necessary
      \draw (0,0) to[short,-*] (1,0) -- (1,1) to[R, l=$R_1$] (3,1) to[short,-*]
        (3,0) -- (4,0) coordinate(end1);
      \draw (1,0) -- (1,-1) to[R, l=$R_2$] (3,-1) -- (3,0);
    \end{scope}
    \path
      (end1)++(0.5,0)
      node[anchor=west](lr){$\Longleftrightarrow$}
      ;
    \begin{scope} % not really necessary
      \draw (lr.east)++(.5,0) to[R, l=$R$] ++(3,0);
    \end{scope}
  \end{circuitikz}
\end{center}
\[
  R = \frac{1}{\frac{1}{R_1}+\frac{1}{R_2}} \Longleftrightarrow R
    = \left( \sum_n\frac{1}{R_n} \right)^{-1}
\]
\end{document}

enter image description here

2
  • Perhaps with a TikZ matrix, one could get a more aesthetic result with formulas centred under their circuit.
    – projetmbc
    Mar 5 at 11:32
  • 1
    @projetmbc the formulae are not directly linked to either of the circuits, both fully describe the two circuits and how they are equivalent.
    – Skillmon
    Mar 5 at 11:46
5

Although I would use @Skillmon method here (centering the arrow would be quite complex here, see Vertical alignment of tikz circle in equation, for example), is good to know the existence of the baseline option to TikZ (and so circuitikz) pictures. You can feed it a coordinate or a node, and it will consider this coordinate or node the vertical position around which the whole picture is aligned vertically.

\documentclass[border=3.14,preview]{standalone}

\usepackage{circuitikz}

\begin{document}
\begin{center}
      \begin{circuitikz}[baseline={(0,0)}]
      \draw (0,0) to[short,-*] (1,0) -- (1,1) to[R, l=$R_1$] (3,1) to[short,-*]
        (3,0) -- (4,0) coordinate(end1);
      \draw (1,0) -- (1,-1) to[R, l=$R_2$] (3,-1) -- (3,0);
  \end{circuitikz}\quad
  \tikz [baseline] \draw (0,0) node{$\Longleftrightarrow$};
  \quad
  \begin{circuitikz}[baseline={(0,0)}]
      \draw (0,0) to[R, l=$R$] ++(3,0);
  \end{circuitikz}
\end{center}
\[
  R = \frac{1}{\frac{1}{R_1}+\frac{1}{R_2}} \Longleftrightarrow R
    = \left( \sum_n\frac{1}{R_n} \right)^{-1}
\]
\end{document}

enter image description here

1
  • You could align the arrows using saveboxes, \hphantom, \mathllap and \mathrlap (mathtools). Mar 5 at 15:38

You must log in to answer this question.

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