I want to draw lines for dimensions with the command \draw[|<->|]...;
. In addition, I have line to some other objects, whose dimensions should be stated. However, the lines from the arrow option |<->|
are a bit shifted compared to the perpendicular line at the same coordinates. Is there a way to correct this automatically and not manually, like I did it in the example? Subtracting the half line width is only applicable, if the direction of the arrow is known, and only easy, if it's along the coordinate system.
MWE
\documentclass[convert={density=1000}]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[gray] (0,0) -- (0,0.5);
\draw[gray] (1,0) -- (1,0.5);
\draw[|<->|] (0,0.125) -- (1,0.125);
\draw[|<->|] (0-\pgflinewidth/2,0.375) -- (1cm+\pgflinewidth/2,0.375);
\end{tikzpicture}
\end{document}
Output
Edit:
The suggested answer uses \pgfarrowsdeclare
, which seems to be deprecated, as stated in this question. I'll try to solve my question with the current command, \pgfdeclarearrow
. With it I can simply write
\pgfdeclarearrow{name=dim-dim, means={>.|[sep=-0.25pt]},}
which is a very short solution and almost does what I want. The only drawback is that it is not possible for me to use \pgflinewidth
instead of the manual value -0.25pt
. This results in the error Missing \endcsname inserted.
, if I try to compile the following code:
\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
%\pgfdeclarearrow{name=dim-dim, means={>.|[sep=-0.25pt]},}
\pgfdeclarearrow{name=dim-dim, means={>.|[sep=-\pgflinewidth]},}
\begin{document}
\begin{tikzpicture}
\draw[gray] (0,0) -- (0,1);
\draw[gray] (1,0) -- (1,1);
\draw[dim-dim] (0,0.5) -- (1,0.5);
\end{tikzpicture}
\end{document}
Is there a way to overcome this error?