自动将节点定位到线上

自动将节点定位到线上

我在移动时间轴的节点时遇到了问题。无论文本有多长,我都希望节点的位置始终像示例中的第一个节点一样。我该怎么做?我对 LaTeX 还很陌生,所以如果可能的话请 ELI5。

提前致谢!

代码:

\begin{tikzpicture}
\draw[-stealth] (0,0) -- (25,0);
\foreach \x in {0,2,4,6,8,10,12,14,16,18,20,22,24} \draw (\x cm,3pt) -- (\x,-3pt);

\draw (0,0) node[below=3pt] {Nov/Dez} node[right=10pt,above=10pt,rotate=45] {iod};
\draw (2,0) node[below=3pt] {445 v.Chr.} node[right=20pt,above=20pt,rotate=45] {sjfiosjfeiojfweofejiod};
\draw (4,0) node[below=3pt] {Jan/Feb} node[above=3pt] {slejfeoijf};
\draw (6,0) node[below=3pt] {Feb/März} node[above=3pt] {};
\draw (8,0) node[below=3pt] {März/Apr} node[above=3pt] {};
\draw (10,0) node[below=3pt] {Apr/Mai} node[above=3pt] {};
\draw (12,0) node[below=3pt] {Mai/Jun} node[above=3pt] {};
\draw (14,0) node[below=3pt] {Jun/Jul} node[above=3pt] {};
\draw (16,0) node[below=3pt] {Jul/Aug} node[above=3pt] {};
\draw (18,0) node[below=3pt] {Aug/Sept} node[above=3pt] {};
\draw (20,0) node[below=3pt] {Sept/Okt} node[above=3pt] {};
\draw (22,0) node[below=3pt] {Okt/Nov} node[above=3pt] {};
\draw (24,0) node[below=3pt] {Nov/Dez} node[above=3pt] {};
\end{tikzpicture}

输出:

输出

答案1

使用ROT样式,例如像这样ROT/.style={above,rotate=45,anchor=south west},所有节点都会选择[ROT]遵循相同的行为。您可以above=5pt根据需要选择将标签稍微向上抬起一点。

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}[ROT/.style={above,rotate=45,anchor=south west}]
\draw[-stealth] (0,0) -- (25,0);
\foreach \x in {0,2,4,6,8,10,12,14,16,18,20,22,24} \draw (\x cm,3pt) -- (\x,-3pt);

\draw (0,0) node[below=3pt] {Nov/Dez} node[ROT] {iod};
\draw (2,0) node[below=3pt] {445 v.Chr.} node[ROT] {sjfiosjfeiojfweofejiod};
\draw (4,0) node[below=3pt] {Jan/Feb} node[ROT] {slejfeoijf};
\draw (6,0) node[below=3pt] {Feb/März} node[above=3pt] {};
\draw (8,0) node[below=3pt] {März/Apr} node[above=3pt] {};
\draw (10,0) node[below=3pt] {Apr/Mai} node[above=3pt] {};
\draw (12,0) node[below=3pt] {Mai/Jun} node[above=3pt] {};
\draw (14,0) node[below=3pt] {Jun/Jul} node[above=3pt] {};
\draw (16,0) node[below=3pt] {Jul/Aug} node[above=3pt] {};
\draw (18,0) node[below=3pt] {Aug/Sept} node[above=3pt] {};
\draw (20,0) node[below=3pt] {Sept/Okt} node[above=3pt] {};
\draw (22,0) node[below=3pt] {Okt/Nov} node[above=3pt] {};
\draw (24,0) node[below=3pt] {Nov/Dez} node[above=3pt] {};
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

您可以使用event/.style={anchor=south west,rotate=45,outer sep=2pt}

\documentclass[tikz,border=7pt]{standalone}
\begin{document}
  \begin{tikzpicture}[event/.style={anchor=south west,rotate=45,outer sep=2pt}]
    \draw[-stealth] (2,0) -- +(25,0);
    \foreach[count=\i] \m in {Nov/Dez,445 v.Chr.,Jan/Feb,Feb/März,März/Apr,Apr/Mai,Mai/Jun,Jun/Jul,Jul/Aug,Aug/Sept,Sept/Okt,Okt/Nov,Nov/Dez}{
      \draw ({2*\i},-3pt) -- +(0,6pt) node[midway, below=3pt] {\m};
    }
    % events
    \foreach \x/\y in {1/iod,2/sjfiosjfeiojfweofejiod,3/slejfeoijf}
      \node[event] at ({2*\x},0) {\y};
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容