假设我们有 2 个电阻器,一个在正 x 轴上,一个在负 x 轴上,如下所示:
我想R
使用一个节点来标记它们,该节点的南锚点位于电阻的北锚点。我对其他标记方式不感兴趣。奇怪的是,当我们使用上面提到的锚点时,标记的结果不会是对称的。一个右标签在 y 方向上将高于左标签。你知道为什么吗?如何修复它?下面是我的代码:
\documentclass[border=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary {circuits.ee.IEC}
\begin{document}
\begin{tikzpicture}[circuit ee IEC,set resistor graphic=var resistor IEC graphic]
\draw [ help lines,xstep=.5cm,ystep=.5cm] (-2cm,-0.5cm) grid (2cm,0.5cm);
%drawing the positive x-axis resistor
\draw (0,0cm) to [resistor={name=roxp,pos=0.5 } ] (2cm,0);
\node [anchor=south]at (roxp.north){$R$};
%drawing the negative x-axis resistor
\draw (0,0cm) to [resistor={name=roxn,pos=0.5 } ] (-2cm,0);
\node [anchor=south]at (roxn.north){$R$};
\end{tikzpicture}
\end{document}
答案1
根据我对旋转组件锚点的评论(尽管我更喜欢使用[l=$R$]
简单性)。
\documentclass[border=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary {circuits.ee.IEC}
\begin{document}
\begin{tikzpicture}[circuit ee IEC,set resistor graphic=var resistor IEC graphic]
\draw [ help lines,xstep=.5cm,ystep=.5cm] (-2cm,-0.5cm) grid (2cm,0.5cm);
%drawing the positive x-axis resistor
\draw (0,0cm) to [resistor={name=roxp,pos=0.5 } ] (2cm,0);
\node [anchor=south]at (roxp.north){$R$};
%drawing the negative x-axis resistor
\draw (0,0cm) to [resistor={name=roxn,pos=0.5 } ] (-2cm,0);
\node [anchor=south]at (roxn.south){$R$};
\end{tikzpicture}
\end{document}
答案2
您是否因为某些特殊原因不使用选项info
或info'
?使用它,可以绘制显示图(无需担心电阻锚点),如下所示:
\documentclass[border=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary {circuits.ee.IEC}
\begin{document}
\begin{tikzpicture}[circuit ee IEC,
set resistor graphic=var resistor IEC graphic]
\draw [help lines,xstep=.5cm,ystep=.5cm] (-2cm,-0.5cm) grid (2cm,0.5cm);
%drawing the positive x-axis resistor
\draw (0,0) to [resistor={info=$R$} ] (2,0);
%drawing the negative x-axis resistor
\draw (0,0) to [resistor={info'=$R$} ] (-2,0);
\end{tikzpicture}
\end{document}
编辑:
显然,OP 确信他/她可以手动更好地调整标签位置,因为这是通过使用info
选项获得的刻意定义的自动定位来完成的。
无论如何,对于一个电阻器,可以按照以下方式完成:
\begin{tikzpicture}[line cap=rect]
\node[name=s,shape=var resistor IEC, draw,
minimum width=2cm,minimum height=0.4cm] {} (2,0);
\node[above=3mm] at (s.north) {$R$};
\draw (s.west) -- ++ (-0.5,0);
\end{tikzpicture}
对于其他可能性,请参见我在下面的评论中提到的电阻锚位置草图。