以下代码显示问题
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits}
\begin{document}
\begin{tikzpicture}[circuit]
\draw (0,0) to [circuit handle symbol={draw,shape=rectangle,at start}] (0,3);
\draw (1,3) to [circuit handle symbol={draw,shape=rectangle,at end}] (1,0);
\end{tikzpicture}
\end{document}
这是在升级到最新版本的 pgf 之前编译的,输出符合预期。以小矩形结尾的两条线应该是相同的,但在这种情况下,at end
矩形似乎被旋转了,因此将路径的终点从预期的终点移开了。
我现在想要使用我的 tikzets 中的参数来控制这种行为,因为我的绘图库中当然有大量这样的 tikzets。
答案1
您说得对;当节点添加在 时pos=1
(并且仅在此时),就会出现问题。似乎锚点(相对于节点)始终位于west
。
我认为有两种方法可以处理这种情况:要么使用anchor=south
,或者根据当前情况使用任何方便的方法,或者使用pos=.999
。我更喜欢后者。
\documentclass[11pt, border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{circuits}
\begin{document}
\begin{tikzpicture}[circuit,
every node/.style={scale=.7},
every label/.style={text=black, scale=.9}]
\draw[gray, very thin, dashed] (-2, -1) grid (7, 5);
\draw[thick]
(-2, 0) node[fill=white] {start level} -- +(1.5, 0)
(-2, 4) node[fill=white] {end level} -- +(1.5, 0);
\draw[blue, thick] (0, 0) to [
circuit handle symbol={draw, shape=rectangle, fill=yellow, at start},
circuit handle symbol={draw, shape=rectangle, pos=.7},
circuit handle symbol={draw, shape=rectangle, at end}
] +(2, 4);
\draw[red, thick] (2, 0) to [
circuit handle symbol={draw, shape=rectangle, fill=yellow, at start},
circuit handle symbol={draw, shape=rectangle, pos=.7},
circuit handle symbol={%
draw, shape=rectangle, at end, anchor=south,
label={[above]80:{with anchor=south}}
}] +(2, 4);
\draw[red, thick] (4, 0) to [
circuit handle symbol={draw, shape=rectangle, fill=yellow, at start},
circuit handle symbol={draw, shape=rectangle, pos=.7},
circuit handle symbol={%
draw, shape=rectangle, pos=.9999,
label={[above right, text width=5em]90:with pos=.9999}
}] +(2, 4);
\end{tikzpicture}
\end{document}