9

I'd like to place custom formatted nodes relative to the legend in a plot. The answer to Placing node relative to legend is a solution per se, but related to op's actual intent so it isn't helpful to me. It's not what I want, as the picture below should show: one could wish to either place the node below of the legend. In this case it should be, imho, aligned be the right border of both nodes. If the legend were placed somewhere else, or the node, obviously the alignment could be along the top borders of both elements... and so forth.

So far I started to fiddle around with some trial and error to get there but it isn't satisfactory yet, by far. Besides, having a good method for anchoring the node should be way faster.

Please disregard the overlapping of the graph and the node.

Picture

enter image description here

MWE

\documentclass[
a4paper
]{scrartcl}

\usepackage{
amsmath,
tikz,
pgfplots,
}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
\begin{axis}[
xlabel={Bla},
ylabel={Process},
%
legend style={label=below:bla},
]
\addplot+ {rand};
\addlegendentry{Stuff}
%
\node[fill=white, draw, align=center, font=\scriptsize, anchor=north east] at (axis cs:5.5,0.5) {Word: Text}; %<----- What I would actually like to use!
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

1 Answer 1

12

(I'm not entirely sure if this is what you're after.)

By adding name=leg to the legend style, the legend box will get the (node) name leg. You can add nodes relative to this, if you place them outside the axis. For example:

\documentclass[
a4paper
]{scrartcl}

\usepackage{
amsmath,
tikz,
pgfplots,
}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
\begin{axis}[
xlabel={Bla},
ylabel={Process},
%
legend style={name=leg},
]
\addplot+ {rand};
\addlegendentry{Stuff}
%
\end{axis}

\node[fill=white, draw, align=center, font=\scriptsize, below=1mm, anchor=north east] (1) at (leg.south east) {Word: Text};
\node[fill=white, draw, align=center, font=\scriptsize, below=1mm, anchor=north east] at (1.south east) {Word: Longer Text}; 
\end{tikzpicture}
\end{center}
\end{document}
0

You must log in to answer this question.

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