有一种方便的方法可以相对于路径定位阳极:我将节点 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}