Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using the awesome pgfplots package to draw some plots. I usually use \addlegendentry and get a nice default legend box. There are some options for legend box placement and layout (e.g. number of columns).

For some plots I would like to add a title inside the legend box.

Could not find the something about this in the manual. Does anyone know what is the way to customize the legend box?

share|improve this question
add comment

1 Answer

up vote 10 down vote accepted

You could perhaps use the \addlegendimage command, as in this discussion from the pgfplots-features mailing list.

An example, with a small \hspace hack to place the title more centered in the legend box:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[legend pos=south east]
   \addlegendimage{empty legend}
   \addplot {sqrt(x)}; 
   \addplot {ln(x)}; 

   \addlegendentry{\hspace{-.6cm}\textbf{A title}}
   \addlegendentry{$\sqrt{x}$}
   \addlegendentry{$\ln{x}$}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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