我遇到了以下问题:当我使用 circuitikz 绘制电路时,我无法在电路侧面添加一些图形来使其居中。看看我的代码。问题是环境将电路和红线视为同一个图形,因此 latex 同时将它们居中。我想要做的是将电路置于 \textwidth 中间,然后将红线及其标签放在居中电路的侧面。可以吗?这是代码:
\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
当然可以。如果你把东西放在overlay
范围内,它不会被考虑在边界框的确定中,因此不会影响电路的位置。从道德上讲,这与samcarter 最近的回答,其中pgfinterruptboundingbox
使用了 ,效果相同。为了说明,我还标出了页面的文本区域以及中间部分,并overlay
与进行比较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}