7

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?

9

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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.