1

I have the following problem: when I draw a circuit using circuitikz I can't center it when I add some figures on its side. Take a look at my code. The problem is that the environment considers both circuit and the red line as the same figure, so latex center them at the same time. What I would like to do is to center just the circuit in the middle of the \textwidth, and then put the red line with its label on the side of the centered circuit. Is it possible? Here's the code:

\documentclass[a4 paper]{book}

\usepackage{tikz}
\usepackage{circuitikz}

\begin{document}
This is the circuit This is the circuit This is the circuit This is the circuit 
\begin{figure}[h]
\centering
\begin{circuitikz}
 \draw (0,0) to [sI](0,2)--(3,2)to[generic](3,0)--(0,0);
 \draw[->,red](-0.6,0.5)--(-0.6,1.5)node
  [red, left, midway]{$Current$};
\end{circuitikz}
\end{figure}
\end{document}

1 Answer 1

1

Yes, of course. If you put stuff in an overlay scope, it will not be taken into account for the determination of the bounding box, and thus not affect the position of the circuit. Morally, this is the same answer as samcarter's recent answer, in which pgfinterruptboundingbox is used, which has the same effect. For illustration, I also indicate the text area of the page as well as its middle, and compare overlay to no overlay.

\documentclass[a4 paper]{book}

\usepackage{tikz}
\usepackage{circuitikz}
\usepackage{tikzpagenodes} % only for illustration
\begin{document}
This is the circuit This is the circuit This is the circuit This is the circuit 
\begin{figure}[h]
\centering
\begin{circuitikz}
 \draw (0,0) to [sI](0,2)--(3,2)to[generic](3,0)--(0,0);
 \begin{scope}[overlay]
 \draw[->,red](-0.6,0.5)--(-0.6,1.5)node
  [red, left, midway]{Current};
 \end{scope} 
\end{circuitikz}
\caption{With \texttt{overlay}.}
\end{figure}

\begin{figure}[h]
\centering
\begin{circuitikz}
 \draw (0,0) to [sI](0,2)--(3,2)to[generic](3,0)--(0,0);
 \draw[->,red](-0.6,0.5)--(-0.6,1.5)node
  [red, left, midway]{Current};
\end{circuitikz}
\caption{Without \texttt{overlay}.}
\end{figure}
% only for illustration
\begin{tikzpicture}[overlay,remember picture]
  \draw[blue] (current page text area.north)  -- (current page text area.south);
  \draw[blue] (current page text area.north west)  rectangle 
  (current page text area.south east);
\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

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