1

I use circuitikz a lot for circuit diagrams and many of them involve some kind of a circuit element at the bottom which makes the diagram "asymmetric" or "not a perfect rectangle" (forgive me if there is some technical term that I am missing). From a post I had made previously, I learned about the \frame and \fbox commands which work well for rectangular pictures but not (in my opinion) for diagrans such as these:

actual (actual)

what I want (what I want)

Is there any way to address this without hardcoding values ?

Code for the above:

\frame{
\begin{circuitikz}[european, voltage shift=0.5]
    \draw (0,0) to [isource, l=$I_0$, v=$V_0$] (0,3)
    to [short, -*, i=$I_0$] (2,3)
    to [R=$R_1$, i>_=$i_1$] (2,0) -- (0,0); 
    \draw (2,3) -- (4,3)
    to [R=$R_2$, i>_=$i_2$]
    (4,0) to [short, -*] (2,0);
\end{circuitikz}
}

Edit I realize there is also a bit of asymmetry in the horizontal direction which I have not removed in the "what I want" figure but I would like for that to be fixed as well. Is this possible ?

  • 3
    You should post a code that compiles. – projetmbc Mar 09 '21 at 21:11
  • 1
    I guess at the end it's a question of taste. The system will not hit your favorite parameters. Imagine you had the current I_0 below, then the bounding box would be too narrow on top. Maybe you could draw a rectangle with a dimension of the circuit lines plus something to the left, right, top and bottom. – Harald Lichtenstein Mar 09 '21 at 21:31
  • 1
    I would avoid the external frame and create one with a fit node. Create the node using as fit sources four nodes you think are symmetrical, then add an inner sep (or inner ysep / xsep). Look at the fit library in TikZ manual. – Rmano Mar 09 '21 at 21:52

2 Answers2

2

The simple way to do it is drawing a rectangle with tikz, which I added to your code:

\documentclass[border=2mm]{standalone}
\usepackage   [EFvoltages]{circuitikz}

\begin{document} \begin{circuitikz}[european, voltage shift=0.5] \draw (0,0) to [isource, l=$I_0$, v=$V_0$] (0,3) to [short, -*, i=$I_0$] (2,3) to [R=$R_1$, i>_=$i_1$] (2,0) -- (0,0); \draw (2,3) -- (4,3) to [R=$R_2$, i>_=$i_2$] (4,0) to [short, -*] (2,0); \draw[thick] (-1,-1) rectangle (5,4); % the frame \end{circuitikz} \end{document}

This is what I get: enter image description here

Juan Castaño
  • 28,426
2

This is to show the approach I hinted at in the comment; please read the comments in the file. The fit library is very useful and explained in the TikZ manual. The focus in this solution is that you can decide what is "in" the main image (and you want the box symmetric with) and what is "out", to be ignored. In my first example, I will ignore all that sticks out the main rectangle; in the second one, basically, the only ignored thing is the label $I=0$ on the top.

This is the whole code; I will post the images below it with only the red or the blue boxes uncommented, to make it clearer.

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}[european, voltage shift=0.5]
    % naming coordinate here
    \draw (0,0) to [isource, l=$I_0$, v=$V_0$, name=sI0] (0,3) coordinate(top l)
        to [short, -*, i=$I_0$] (2,3)
        to [R=$R_1$, i>_=$i_1$] (2,0) -- (0,0) coordinate(bottom l);
    \draw (2,3) -- (4,3) coordinate(top r)
        to [R=$R_2$, i>_=$i_2$, name=R2]
        (4,0) coordinate(bottom r) to [short, -*] (2,0);
    %
    % using fit, we find the box that we want to use as the part we want
    % to use when pasting the "symmetric box" around the figure. The red
    % thin one is just to show the basic box, the thick one is the resulting
    % box
    %
    \node[draw, thin, dashed, red,
        fit=(top l) (bottom l) (top r) (bottom r), inner sep=0pt](){};
    \node[draw, red,
        fit=(top l) (bottom l) (top r) (bottom r),
        inner xsep=1cm, inner ysep=0.5cm](){};
    %
    % you can add other nodes to the fit thing too. For example, let's decide
    % that the source and R2, with the labels, are to be considered for the
    % symmetry (blue lines)
    %
    \node[draw, thin, dashed, blue,
        fit=(top l) (bottom l) (top r) (bottom r) (sI0label) (R2label),
        inner sep=0pt](){};
    \node[draw, blue,
        fit=(top l) (bottom l) (top r) (bottom r) (sI0label) (R2label),
        inner sep=0.5cm](){};
\end{tikzpicture}
\end{document}

With just the red boxes:

enter image description here

With just the blue ones:

enter image description here

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • 1
    @first-user, please also notice how an minimal working example (MWE) is built and why it's important. The direction of the voltages in my example are different due to a different setting in the preamble --- this is why a complete, compilable example is needed most of the time. – Rmano Mar 10 '21 at 08:36