我怎样才能将文本放置在时间线上方相同的高度,即让它们显示在同一行?我认为“p”比“E”高。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[->,>=] (-1,0) -- (9,0);
\draw[shift={(0,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$1$};
\draw[shift={(0,0.8)}] node {p};
\draw[shift={(4,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$2$};
\draw[shift={(4,0.8)}] node {E};
\draw[shift={(8,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$3$};
\draw[shift={(8,0.8)}] node {J};
\end{tikzpicture}
\end{document}
答案1
应用于anchor=base
将使tikzpicture
三项内容与基线保持一致:
代码:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1, anchor=base]
\draw[->,>=] (-1,0) -- (9,0);
\draw[shift={(0,0)}] (0pt,2pt) -- (0pt,-2pt)
node[below] {$1$};
\draw[shift={(0,0.8)}] node {p};
\draw[shift={(4,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$2$};
\draw[shift={(4,0.8)}] node {E};
\draw[shift={(8,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$3$};
\draw[shift={(8,0.8)}] node {J};
\end{tikzpicture}
\end{document}
答案2
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[line width=1pt] (0,0) -- (10,0);
\foreach \x/\y/\z in {1/1/p,5/5/E,9/9/J,}{
\draw[line width=1pt] (\x,-2mm)
node[below](\x){\strut\y} --
(\x,2mm)node[above=0.5cm]{\z};
}
\end{tikzpicture}
\end{document}
基线检查似乎没问题
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[line width=1pt] (0,0) -- (10,0);
\foreach \x/\y/\z in {1/1/p,1.2/1.2/E,1.4/1.4/J,}{
\draw[line width=1pt] (\x,-2mm)
node[below](\x){\strut\y} --
(\x,2mm)node[above=0.5cm]{\z};
}
\end{tikzpicture}
\end{document}