[Tex/LaTex] how to draw a line segment bounded by ticks at end points

tikz-arrows

I want something like this, but I can't make it in a simple and elegent way.

line segment bounded by ticks at end points[![][1]][1]

A similar picture placed below can be plotted using |-|, so I wonder if there is a similar way.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw[|-|] (0,0) -- (2,0);
\end{tikzpicture}
\end{document}

enter image description here

Best Answer

Use [left] or [right] option for arrow heads; see Page 193 of this pgfmanual (version 3.0.1).

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}
  \draw[{|[right]}-{|[left]}, blue] (0,1) to (1,1);  % for your purpose
  \draw[|-|, red] (0,0) to (1,0);
\end{tikzpicture}
\end{document}

tikz-interval-half