![在路径中的相对位置绘制节点](https://linux22.com/image/356996/%E5%9C%A8%E8%B7%AF%E5%BE%84%E4%B8%AD%E7%9A%84%E7%9B%B8%E5%AF%B9%E4%BD%8D%E7%BD%AE%E7%BB%98%E5%88%B6%E8%8A%82%E7%82%B9.png)
有一种方便的方法可以相对于路径定位阳极:我将节点 sigma 设置在中途。但如果我向路径添加“to”组件,则节点不会相应移动。
如何将 sigma 定位在完整路径的中间?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.markings,positioning}
\begin{document}
\tikzset{
nat/.style = {fill=white,draw,ellipse,minimum size=0.5cm,inner sep=1pt},
}
\begin{tikzpicture} -- OK
\draw (0,4) -- (0,2)
node[pos= 0.5,nat] (s) {$\sigma$}
node[pos=0,above] {$k$};
\end{tikzpicture}
\begin{tikzpicture} -- NOT OK
\draw (0,4) -- (0,2) to[out=-90, in=90] (2,0)
node[pos= 0.5,nat] (s) {$\sigma$}
node[pos=0,above] {$k$};
\end{tikzpicture}
\end{document}
Hackish 正确:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.markings,positioning,decorations.text}
\begin{document}
\tikzset{
nat/.style = {fill=white,draw,ellipse,minimum size=0.5cm,inner sep=1pt},
}
\begin{tikzpicture}
\draw(0,4) -- (0,2) to[out=-90, in=90] (2,0)
node[pos=0,above] {$k$};
\draw[draw=none] (0,2) -- (2,0)
node[midway,nat] (s) {$\sigma$};
\end{tikzpicture}
\end{document}
答案1
更改后at position 0.5
您可以选择您想要的任何位置。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.markings,positioning}
\begin{document}
\tikzset{
nat/.style = {fill=white,draw,ellipse,minimum size=0.5cm,inner sep=1pt},
}
\begin{tikzpicture}
\draw[postaction={decorate, decoration={markings,mark=at position 0.5 with {\node[nat] {$\sigma$};}}}]
(0,4) node[above] {$k$} -- (0,2) to[out=-90, in=90] (2,0);
\end{tikzpicture}
\end{document}