# Use a LaTeX length for an arrow head length in TikZ

I draw an arrow in Tikz and I want to specify the length with a LaTeX length, e.g., \headlength, instead of explicitly writing the length, e.g., 2em. However, it seems that the TikZ does not like LaTeX lengths as input for the length of the arrow head. (See example below)

How could I give a LaTeX length to the option length=? (Thanks!)

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

\begin{document}

\begin{tikzpicture}
\draw[-{Latex[length=2em]}] (0,0) -- (2,0); %It works!
\draw[-{Latex[length=\headlength]}] (0,1) -- (2,1); %It outputs error
\end{tikzpicture}

\end{document}


You can use \the\headlength.

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

\begin{document}

\begin{tikzpicture}
\draw[-{Latex[length=2em]}] (0,0) -- (2,0); %It works!
\draw[-{Latex[length=\the\headlength]}] (0,1) -- (2,1); %Works as well
\end{tikzpicture}

\end{document}


Allocate registers in the preamble, not inside the tikzpicture.

• Do you know where to look in the manual for "\the"? (my viewer(mac preview) refuses to search for "\the") – hpekristiansen Jun 21 at 10:50
• @hpekristiansen See tex.stackexchange.com/q/38674/4427 – egreg Jun 21 at 12:04
• Great. very handy solution. Now I understand that TikZ does not takes LaTeX lengths (registers) in the option length, but just "text". – loved.by.Jesus Jun 21 at 12:38

I found a quick fix via math library (I am not satisfied: it looks like a patch and I do not understand why it works)

Just store the LaTeX length in a tikzmath variable and voilà.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{math}

\begin{document}