3

How can I position the text above the time line in same height, i. e. so that they appear as being on the same line? I think the "p" is higher than the "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}

enter image description here

1
  • have a look at the answer below please
    – js bibra
    Feb 15, 2021 at 16:25

2 Answers 2

4

Applying anchor=base to the tikzpicture will align the three items at the baseline:

enter image description here

Code:

\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}
0

enter image description here

\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}

baseline check seems ok

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .