28

Here is my problematic code:

\begin{tikzpicture}
\draw  (0,0)  to [bend left=20] (3,3) node[midway] {midway label};
\end{tikzpicture}

I wanted to put a label midway of the line, but instead the label is at (0,0).

If I remove [bend left=20], the line is not bent, and the label still misplaced. If I remove to and replace it by --, then it works fine, but my line is not bent any more.

\begin{tikzpicture}
\draw (0,0) -- (3,3) node[midway] {midway label};
\end{tikzpicture}

Works fine.

The problem occurs with MacTeX 2011 and MacTeX 2012.

1
  • Hi Loick, welcome to TeX.sx! It's generally preferred to post full compilable examples instead of just snippets. And a tip: Inline code (like the [bend left=20] in your post) can be formatted by enclosing them in backticks.
    – Jake
    Jul 22, 2012 at 9:29

2 Answers 2

38

You should move node[midway] {midway label} before the last coordinate.

Some examples:

\documentclass[11pt,a4paper]{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw  (0,0)  to [bend left=20] node[midway] {midway label}(3,3) ;
\draw[xshift=4cm]  (0,0)  to [bend left=20] node[midway,left] {midway label}(3,3) ;
\draw[xshift=6cm]  (0,0)  to [bend left=20] node[midway,right] {midway label}(3,3) ;
\end{tikzpicture}

\begin{tikzpicture}
\draw  (0,0)  to [bend left=20] node[sloped,midway,above] {midway label}(3,3) ;
\end{tikzpicture}
\end{document}

enter image description here

2
  • Can left be set as 3/4 of the positon (like sliding little bit to the right)?
    – alper
    Mar 5, 2021 at 20:16
  • @alper: sure, you can play with the right keys to achieve the desired result. If you mean the label, then use pos= rather than midway (which is a shortcut for pos=0.5). If you mean the bending, then play with the angle. Mar 8, 2021 at 8:38
17

You can also use the pos=<value from 0 to 1> key (see manual section 16.8) to specify where on your curve the node should be. A little example illustrating this for 0.1 increments from 0 to 1:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm,landscape]{geometry}
\usepackage{tikz}

\begin{document}

\foreach \x in {0,0.1,...,1}
{   \begin{tikzpicture}[scale=0.2]
    \draw  (0,0)  to [bend left=20] node[pos=\x,fill=red,circle,inner sep=2pt] {} (3,3) ;
    \end{tikzpicture}
}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .