43

I think it is a simple question, but I didn't find the answer yet. The code I'm using is the following:

\draw[->](1,0) arc(0:-30:1) node[midway]{$30$};

But in this way the node is placed at the origin intead of at the middle of the arc.

Note: it must be done with arc.

5 Answers 5

38

As of 2012-03-01, thanks to Till Tantau, it is now possible to do it straightforwardly with the cvs version of pgf-tikz. It has been included since in the stable version of pgf-tikz.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \draw[->](1,0) arc(0:-30:1) node[midway]{$30$};
\end{tikzpicture}
\end{document}

enter image description here

5
  • What exactly means csv version - does this mean this option is going to become official at one point?
    – Pygmalion
    Commented Mar 23, 2013 at 7:25
  • @pygmalion yes. The CVS version is the development version that will become one day the official one.
    – cjorssen
    Commented Mar 23, 2013 at 10:11
  • Thank you for your answer. Since you are already acknowledged with the CSV version, is it possible to make node in the middle of the arc, but on left or right side of it? Like [midway] and [midway,swap] when driving lines? If not, I will open request on TikZ development.
    – Pygmalion
    Commented Mar 23, 2013 at 19:00
  • I am sorry for bothering again, but I still don't understand. Last official version is 2.10, dated 2012-08-19, which is beyond the time you mentioned above. And this version still does not provide [midway] solution for the arcs. Am I missing something? I just don't get it.
    – Pygmalion
    Commented May 29, 2013 at 11:27
  • @Pygmalion You need the cvs version (that is the devel version) of tikz. It's been a long time since the last official release. For the installation, see this answer.
    – cjorssen
    Commented May 29, 2013 at 19:02
18

The reason why it is shown at the origin is because there is no explicit second coordinate for TikZ to interpolate via pos. One solution is to, roughly speaking, parameterize the arc path via markings library. This is simply a modification of my previous answer for marking a path with a node.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
arcnode/.style 2 args={                
            decoration={
                        raise=#1,             
                        markings,   
                        mark=at position 0.5 with { 
                                    \node[inner sep=0] {#2};
                        }
            },
            postaction={decorate}
}
]
\draw[->, arcnode={20pt}{$30$} ] (0,0) arc (0:-30:2cm) ;
\end{tikzpicture}
\end{document}

labelled curve with offset label

For some reason, when the curved paths become too short(e.g. your example path starts working after 1.095cm for radius of the arc) it gives a Dimension too large error, so probably, there is a detail that I don't know yet here. This is not the case for straight paths.

4
  • When the curved paths become too short, there is a problem with pgfmath see tex.stackexchange.com/questions/20833/… Commented Dec 19, 2011 at 11:03
  • @Altermundus Ouch! I remember reading your discussion on your question but forgot it completely. Thanks, for the reminder. I guess there is no easy way out for this.
    – percusse
    Commented Dec 19, 2011 at 11:14
  • But is there anyway to have it push out a given radius away from the curve?
    – Richard
    Commented Jun 9, 2012 at 6:53
  • @Richard You can use above,leftetc. options in the node to take it out of the curve but I'm not sure if I understand your question. Can you explain it a little more, if possible? If the comment box is not sufficient for it, post a new question and we can have look at it together.
    – percusse
    Commented Jun 9, 2012 at 9:19
12

Problem taken from: Draw centered label above arc in TikZ


This is another approach to this problem. In this way, there is another second coordinate.

\documentclass[tikz,border=5pt]{standalone}
\begin{document}
\begin{tikzpicture}
    \draw[green] (1,0) arc[radius = 1, start angle=0, end angle=90] node[above] {H} arc[radius = 1, start angle=90, delta angle=90];
\end{tikzpicture}
\end{document}

enter image description here

3
  • Wonder if there is a way to not have to repeat most of the info for the node. Commented Oct 12, 2012 at 0:48
  • @PeterGrill I tried putting all between the from arc to ; in a macro but it breaks with a lot of Missing character: There is no [ in font nullfont!. The full TikZ command is possible, but then it's an isolated path. Commented Oct 12, 2012 at 0:56
  • Might work better as a style, but I don't have enough experience to do those, especially since this one would require a parameter. Something like @percusse's solution here of using an arcnode. Anyway, this something I need to learn so was just thinking about it. Commented Oct 12, 2012 at 1:05
4

Major newbie here but here is the way I did it. I was drawing arcs centered at the origin but seems like it should work for others too.

\draw (0.3,0) arc (0:30:0.3) node at (15:0.5) {$\varphi$};
1
  • 6
    Hi bjd, welcome to the site! That's a nice and pragmatic approach (+1), but I think the question was concerned with finding an automatic way to place the node. By the way, you can format code snippets in a post by selecting the text and then clicking the {} button in the editor. Looking forward to seeing you around the site!
    – Jake
    Commented Jul 25, 2013 at 22:11
3

This solution does not rely on arc, but may be helpful for people looking for a simple solution to draw a curved line with a centered label.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\path[->] (1,0)  edge  [bend left=20]  node[above] {$30$} (2,0);
\end{tikzpicture}
\end{document}

enter image description here

Changing "left bend" allows you to adjust the curvature.

1
  • +1 Only this ordering seem to with curve to. @Experts in tikz, please correct me if I am wrong. Commented Dec 14, 2023 at 6:38

You must log in to answer this question.

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