# label arrow at midpoint in tikz

In tikzcd I know of the 'description' qualifier which places the node with a white background on top of and in the middle of the arrow. How can this best be achieved in tikz?

midway and above

\documentclass[margin=2pt]{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw[->](0,0)--(2,0) node[midway,above]{label}; %if you want to enforce a white background add fill=white to the node options
\end{tikzpicture}

\end{document}


Second try:

\documentclass[margin=2pt]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[->](0,0)--(2,0) node[midway,fill=white]{label}; %for better vertical alignment you can add text height=.5em to the node options or a \strut inside the node text
\end{tikzpicture}

\end{document}


• Thanks, but I want the label to be on the arrow not above it. e.g. ---label--->. – Alex Oct 10 '14 at 15:29
• Ah great. I actually tried that but I had 'auto' in tikzset which was the problem I think. – Alex Oct 10 '14 at 15:40
• yup, it was auto that prevented it to work. – Nico Boni Oct 10 '14 at 15:43