# Rotate dimline label to horizontal

I want to rotate a label for my dimline to always be horizontal without having to calculate the rotation angle since they are numerous.

MWE:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tikz}
\usepackage{tikz-dimline}
\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt] (im) at (0,0)
{\includegraphics[scale=1]{example-image}};
\dimline[color = white,
line style = {line width = 0.7},
label style = {anchor = south, fill = none }]
{(-1.2,-1.3)}
{(2,1.6)}
{$w$};
\end{tikzpicture}
\end{document}


## 2 Answers

One has to tell TikZ not to slope.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tikz}
\usepackage{tikz-dimline}
\tikzset{no slope/.code={\pgfslopedattimefalse}}
\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt] (im) at (0,0)
{\includegraphics[scale=1]{example-image}};
\dimline[color = white,
line style = {line width = 0.7},
label style = {above=2mm, fill = none,no slope}]
{(-1.2,-1.3)}
{(2,1.6)}
{$w$};
\end{tikzpicture}
\end{document}


• Thanks for this approach, really easy to implement and change the anchor points change the position of the label! – Mats Nilsson May 9 '18 at 18:46
• check! sorry for the delay. – Mats Nilsson May 9 '18 at 20:29

like this:

but this is drawn by pure tikz:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,quotes}
%\usepackage{tikz-dimline}

\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt] (im) at (0,0)
{\includegraphics[scale=1]{example-image}};
\draw[color = white,{Bar[]Stealth[]}-{Stealth[]Bar[]}, line width = 0.7]
(-1.2,-1.3) to ["$w$"] (2,1.6);
\end{tikzpicture}
\end{document}