[Tex/LaTex] label arrow at midpoint in tikz

tikz-pgf

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?

Best Answer

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}

enter image description here

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}

enter image description here