我创建了两个电路图,尽管完全相同,但它们却没有垂直对齐。这是代码。
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[top=2cm, bottom=2cm, left=2cm, right =2cm]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{steinmetz}
\usepackage{graphicx}
\usepackage{circuitikz}
\usepackage{textcomp}
\usepackage{gensymb}
\newcommand*{\equal}{=}
\begin{document}
\noindent\textbf{\Large Experiment 2.a}\\[7pt]
We are given the following circuit:\\
\begin{tikzpicture}[american voltages]
\draw
(0,4) to[sV, l_=$v_s(t) \equal 2 \cdot \mathrm{sin}(2000\pi \cdot t)$] (0,0)
to [short] (8,0)
to [R, l^=$R_1\equal 1\;\mathrm{k}\ohm$, f<^=$I_r(t)$, v_<=$V_r(t)$] (8,4)
to [pC, l_=$C_1\equal 100\mathrm{nF}$] (5,4)
(0,4) to[L, l^=$L_1\equal 25\mathrm{mH}$] (5,4);
\end{tikzpicture}\\[20pt]
\textbf{1.a Let us find its equivalent circiut in the frequency domain}\\[7pt]
\begin{math}
\mathrm{{\bf V_{s}}}= 2 \cdot \mathrm{sin}\left(2000\pi \cdot t\right)= 2 \cdot \mathrm{cos}\left(2000\pi \cdot t - 90\degree \right) = 2\phase{-90\degree} \text{ V}\\[7pt]
\mathrm{{\bf Z_{L}}}= \mathrm{j}{\omega}L = \mathrm{j}\cdot 2000 \cdot \pi \cdot 25 \cdot 10^{-3} = \mathrm{j}157.07\;\ohm\\[7pt]
\mathrm{{\bf Z_{C}}}=\dfrac{1}{\mathrm{j}{\omega}C}=\dfrac{1}{\mathrm{j}\cdot\pi\cdot100\cdot10^{-9}}=-\mathrm{j}1591.54\;\ohm\\[7pt]
\end{math}\\[10pt]
The frequency domain equivalent of the circuit is as follows:\\[10pt]
\begin{tikzpicture}[american voltages]
\draw
(0,4) to[sV, l_=$\mathrm{{\bf V_{s}}} \equal 2\phase{-90\degree} \text{ V}$] (0,0)
to [short] (8,0)
to [R, l_=$1\;\mathrm{k}\ohm$, f<^=$I_r(t)$,] (8,4)
to [pC, l_=$-\mathrm{j}1591.54\;\ohm$] (5,4)
(0,4) to[L, l^=$\mathrm{j}157.07\;\ohm$] (5,4);
\end{tikzpicture}\\[20pt]
\textbf{1.b Let us find the total impedance linked to the voltage source}\\
$\mathrm{{\bf Z_{T}}}=1000+\mathrm{j}157.07-\mathrm{j}1591.54= \fbox{1000 - 1434.07\;\ohm}$\\[20pt]
\end{document}
答案1
以下将把原点对齐到距左边缘的某个预定义距离。
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[top=2cm, bottom=2cm, left=2cm, right =2cm]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{steinmetz}
\usepackage{graphicx}
\usepackage{circuitikz}
\usepackage{textcomp}
\usepackage{gensymb}
\newcommand*{\equal}{=}
\newsavebox{\tempbox}
\newlength{\tempdima}
\newlength{\origin}
\setlength{\origin}{0.3\textwidth}% distance to tikzpicture origin
\begin{document}
\noindent\textbf{\Large Experiment 2.a}\\[7pt]
We are given the following circuit:\\
\savebox\tempbox{\begin{tikzpicture}[american voltages]
\draw
(0,4) to[sV, l_=$v_s(t) \equal 2 \cdot \mathrm{sin}(2000\pi \cdot t)$] (0,0)
to [short] (8,0)
to [R, l^=$R_1\equal 1\;\mathrm{k}\ohm$, f<^=$I_r(t)$, v_<=$V_r(t)$] (8,4)
to [pC, l_=$C_1\equal 100\mathrm{nF}$] (5,4)
(0,4) to[L, l^=$L_1\equal 25\mathrm{mH}$] (5,4);
\pgfextractx{\tempdima}{\pgfpointanchor{current bounding box}{west}}% negative offset
\global\tempdima=\tempdima
\end{tikzpicture}}%
\hspace*{\dimexpr \origin+\tempdima}\usebox\tempbox\\[20pt]
\textbf{1.a Let us find its equivalent circiut in the frequency domain}\\[7pt]
\begin{math}
\mathrm{{\bf V_{s}}}= 2 \cdot \mathrm{sin}\left(2000\pi \cdot t\right)= 2 \cdot \mathrm{cos}\left(2000\pi \cdot t - 90\degree \right) = 2\phase{-90\degree} \text{ V}\\[7pt]
\mathrm{{\bf Z_{L}}}= \mathrm{j}{\omega}L = \mathrm{j}\cdot 2000 \cdot \pi \cdot 25 \cdot 10^{-3} = \mathrm{j}157.07\;\ohm\\[7pt]
\mathrm{{\bf Z_{C}}}=\dfrac{1}{\mathrm{j}{\omega}C}=\dfrac{1}{\mathrm{j}\cdot\pi\cdot100\cdot10^{-9}}=-\mathrm{j}1591.54\;\ohm\\[7pt]
\end{math}\\[10pt]
The frequency domain equivalent of the circuit is as follows:\\[10pt]
\savebox\tempbox{\begin{tikzpicture}[american voltages]
\draw
(0,4) to[sV, l_=$\mathrm{{\bf V_{s}}} \equal 2\phase{-90\degree} \text{ V}$] (0,0)
to [short] (8,0)
to [R, l_=$1\;\mathrm{k}\ohm$, f<^=$I_r(t)$,] (8,4)
to [pC, l_=$-\mathrm{j}1591.54\;\ohm$] (5,4)
(0,4) to[L, l^=$\mathrm{j}157.07\;\ohm$] (5,4);
\pgfextractx{\tempdima}{\pgfpointanchor{current bounding box}{west}}% negative offset
\global\tempdima=\tempdima
\end{tikzpicture}}%
\hspace*{\dimexpr \origin+\tempdima}\usebox\tempbox\\[20pt]
\textbf{1.b Let us find the total impedance linked to the voltage source}\\
$\mathrm{{\bf Z_{T}}}=1000+\mathrm{j}157.07-\mathrm{j}1591.54= \fbox{1000 - 1434.07\;\ohm}$\\[20pt]
\end{document}
此版本将值保存到辅助文件中,因此需要运行两次才能完成。它会计算自己的共同原点位置。
\placeorigin
应放置在 tikzpicture 的左侧。 \saveorigin
在结束之前进入 tikzpicture 内部。\placeorigin
没有 a\saveorigin
或反之亦然会产生不良结果(但不会崩溃)。
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[top=2cm, bottom=2cm, left=2cm, right =2cm]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{steinmetz}
\usepackage{graphicx}
\usepackage{circuitikz}
\usepackage{textcomp}
\usepackage{gensymb}
\newcommand*{\equal}{=}
\makeatletter
\newcounter{origin}
\newlength{\originmin}
\AtEndDocument{\originmin=-\originmin
\write\@auxout{\string\xdef\string\commonorigin{\the\originmin}}}
\newcommand{\placeorigin}{\bgroup
\stepcounter{origin}%
\@ifundefined{commonorigin}{}{\@ifundefined{origin\theorigin}{}
{\@tempdima=\csname origin\theorigin\endcsname\relax
\hspace*{\dimexpr \commonorigin+\@tempdima}}}%
\egroup\ignorespaces}
\newcommand{\neworigin}[2]% #1 = counter, #2 = value
{\expandafter\xdef\csname origin#1\endcsname{#2}}
\newcommand{\saveorigin}{\bgroup
\pgfextractx{\@tempdima}{\pgfpointanchor{current bounding box}{west}}%
\ifdim\originmin>\@tempdima
\global\originmin=\@tempdima
\fi
\immediate\write\@auxout{\string\neworigin{\theorigin}{\the\@tempdima}}%
\egroup}
\makeatother
\begin{document}
\noindent\textbf{\Large Experiment 2.a}\\[7pt]
We are given the following circuit:\\
\placeorigin
\begin{tikzpicture}[american voltages]
\draw
(0,4) to[sV, l_=$v_s(t) \equal 2 \cdot \mathrm{sin}(2000\pi \cdot t)$] (0,0)
to [short] (8,0)
to [R, l^=$R_1\equal 1\;\mathrm{k}\ohm$, f<^=$I_r(t)$, v_<=$V_r(t)$] (8,4)
to [pC, l_=$C_1\equal 100\mathrm{nF}$] (5,4)
(0,4) to[L, l^=$L_1\equal 25\mathrm{mH}$] (5,4);
\saveorigin% last inside tikzpicture, after \placeorigin
\end{tikzpicture}\\[20pt]
\textbf{1.a Let us find its equivalent circiut in the frequency domain}\\[7pt]
\begin{math}
\mathrm{{\bf V_{s}}}= 2 \cdot \mathrm{sin}\left(2000\pi \cdot t\right)= 2 \cdot \mathrm{cos}\left(2000\pi \cdot t - 90\degree \right) = 2\phase{-90\degree} \text{ V}\\[7pt]
\mathrm{{\bf Z_{L}}}= \mathrm{j}{\omega}L = \mathrm{j}\cdot 2000 \cdot \pi \cdot 25 \cdot 10^{-3} = \mathrm{j}157.07\;\ohm\\[7pt]
\mathrm{{\bf Z_{C}}}=\dfrac{1}{\mathrm{j}{\omega}C}=\dfrac{1}{\mathrm{j}\cdot\pi\cdot100\cdot10^{-9}}=-\mathrm{j}1591.54\;\ohm\\[7pt]
\end{math}\\[10pt]
The frequency domain equivalent of the circuit is as follows:\\[10pt]
\placeorigin
\begin{tikzpicture}[american voltages]
\draw
(0,4) to[sV, l_=$\mathrm{{\bf V_{s}}} \equal 2\phase{-90\degree} \text{ V}$] (0,0)
to [short] (8,0)
to [R, l_=$1\;\mathrm{k}\ohm$, f<^=$I_r(t)$,] (8,4)
to [pC, l_=$-\mathrm{j}1591.54\;\ohm$] (5,4)
(0,4) to[L, l^=$\mathrm{j}157.07\;\ohm$] (5,4);
\saveorigin% last inside tikzpicture, after \placeorigin
\end{tikzpicture}\\[20pt]
\textbf{1.b Let us find the total impedance linked to the voltage source}\\
$\mathrm{{\bf Z_{T}}}=1000+\mathrm{j}157.07-\mathrm{j}1591.54= \fbox{1000 - 1434.07\;\ohm}$\\[20pt]
\end{document}