我刚开始使用 Latex。我正在使用 circuitikz 包。每当我在垂直部分上绘制电压表或电流表时,“A”或“V”都会旋转。我如何使其使用水平基线?此外,如何删除电流表或电压表中的箭头?
\documentclass{article}
\usepackage[american,siunitx,smartlabels]{circuitikz}
\begin{document}
\begin{figure}
\begin{circuitikz}
\draw (0,0)
to [sV=5V] (0,2)
to [R,l=$R_s$] (0,4)
to [C,l=$C$] (4,4)
to [short] (6,4);
\draw (6,0)
to [D] (6,4);
\draw (6,4)
to [short] (8,4)
to [R,l=$R_m$] (8,2)
to [ammeter] (8,0)
to [short] (0,0);
\end{circuitikz}
\end{figure}
\end{document}
答案1
这是一个可能的解决方案。代码中的注释有助于理解该方法:
\documentclass[border=10pt]{standalone}
\usepackage[american,siunitx,smartlabels]{circuitikz}
\ctikzset{bipoles/ammeter/text rotate/.initial=0,% <=new key
rotation/.style={bipoles/ammeter/text rotate=#1},% style for ease introduction in code
}
% code from pgfcircbipoles.sty
\makeatletter
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/ammeter/height}}{ammeter}{\ctikzvalof{bipoles/ammeter/height}}{\ctikzvalof{bipoles/ammeter/width}}{
\def\pgf@circ@temp{right}
\ifx\tikz@res@label@pos\pgf@circ@temp
\pgf@circ@res@step=-1.2\pgf@circ@res@up
\else
\def\pgf@circ@temp{below}
\ifx\tikz@res@label@pos\pgf@circ@temp
\pgf@circ@res@step=-1.2\pgf@circ@res@up
\else
\pgf@circ@res@step=1.2\pgf@circ@res@up
\fi
\fi
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
\pgfpointorigin \pgf@circ@res@other = \pgf@x \advance \pgf@circ@res@other by -\pgf@circ@res@up
\pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@zero}}
\pgfusepath{draw}
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfscope
\pgfpathcircle{\pgfpointorigin}{.9\pgf@circ@res@up}
\pgfusepath{draw}
\endpgfscope
\pgftransformrotate{\ctikzvalof{bipoles/ammeter/text rotate}}% <= magic line
\pgfsetlinewidth{\pgfstartlinewidth}
\pgfsetarrowsend{latex}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@up}}
\pgfusepath{draw}
\pgfsetarrowsend{}
\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@zero}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
\pgfusepath{draw}
\pgfnode{circle}{center}{\textbf{A}}{}{}
}
\makeatother
\begin{document}
\begin{circuitikz}
\draw (0,0)
to [sV=5V] (0,2)
to [R,l=$R_s$] (0,4)
to [C,l=$C$] (4,4)
to [short] (6,4);
\draw (6,0)
to [D] (6,4);
\draw (6,4)
to [short] (8,4)
to [R,l=$R_m$] (8,2)
to [ammeter,rotation=90] (8,0)% introducin rotation
to [short] (0,0);
\end{circuitikz}
\end{document}
结果: