[Tex/LaTex] Multi-line nodes/annotations in pgfplot


It would be great if I could get the annotation in the graph depicted below on two lines, but I can't seem to figure it out.

Presently, I have:

            xlabel={$d_x = w^T_x-w^G_x$},
            ylabel={$s_x = e^{-\frac{d_x^2}{2\sigma^2_x}}$},
    \node[coordinate,pin=-90:{$d_x = 100, s_x = 0.932$}] at (axis cs:100,0.932) {};

Graph with annotation on single line

Looking at a similar question, I've tried changing the \node to:

\node[coordinate,pin=-90:{$d_x = 100$\\$s_x = 0.932$}] at (axis cs:100,0.932) {};

This produces the following error:

There's no line here to end

I've also tried replacing \node with a \draw:

        (axis cs:100,0)
    |-  (axis cs:0,0.8)
    node[near start,left]{$d_y = 100$\\$s_x = 0.932$};

This, too, doesn't seem to want to compile:

Something's wrong; perhaps a missing \item

Best Answer

You need to set the align option in order to get the \\ to work. Try

\node[coordinate, pin={[align=left]-90:{$d_x = 100$,\\$s_x = 0.932$}}]
      at (axis cs:100,0.932) {};

(where you can also choose align=center or whatever if you prefer. Note the extra set of curly braces after pin=.)