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 have a pgfplot where the legend is right to the plot. I create the plot as follows:

\begin{axis}[
    scale only axis,
    xmode=log,
    ymode=log,
    width=7cm,
    legend cell align=left,
    legend pos=outer north east,
    legend style={draw=none}
  ]

Now I would like to move the legend down below the plot. So I thought I have just to replace legend pos=outer north east by legend pos=outer south west. But LaTex does not like this idea: Choice 'outer south west' unknown in key '/pgfplots/le gend pos'. Whats wrong with this?

share|improve this question

1 Answer 1

up vote 11 down vote accepted

From section 4.8.5 of the manual, you can use every axis legend:

\pgfplotsset{every axis legend/.append style={
at={(0,0)},
anchor=north east}} 

Code: (partially from manual )

\documentclass{standalone}
\usepackage{pgfplots}
 \pgfplotsset{width=7cm,compat=1.7}
 \pgfplotsset{every axis legend/.append style={
    at={(0,0)},
    anchor=north east}}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,1) (1,2)};
\addplot coordinates {(0,2) (1,3)};
\legend{$l_1$,$l_2$,$l_3$}
\end{axis}
\end{tikzpicture}
\end{document}

Instead of the /.append style, it is possible to use legend style as in the following example. It has the same effect.

\documentclass{standalone}
\usepackage{pgfplots}
 \pgfplotsset{width=7cm,compat=1.7}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={
at={(0,0)},
anchor=north east}]
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,1) (1,2)};
\addplot coordinates {(0,2) (1,3)};
\legend{$l_1$,$l_2$,$l_3$}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

As percusse mentioned in comment, you can fine tune the position by at={(axis description cs:0,-0.1)} as in:

\documentclass{standalone}
\usepackage{pgfplots}
 \pgfplotsset{width=7cm,compat=1.7}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={
at={(0,0)},
anchor=north east,at={(axis description cs:0,-0.1)}}]
\addplot coordinates {(0,0) (1,1)};
\addplot coordinates {(0,1) (1,2)};
\addplot coordinates {(0,2) (1,3)};
\legend{$l_1$,$l_2$,$l_3$}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
When I try your solution and put anchor=north west, its exactly what I want but the x-axis labels are hidden by the legend. Any proposal how to circumvent this problem? –  Thomas W. Nov 19 '12 at 13:12
    
@ThomasWitkowski Use anchor=north west,at={( xticklabel cs:1)} or anchor=north west,at={(axis description cs:1.05,-0.05)} –  percusse Nov 19 '12 at 13:15
    
If anyone else checks this, one can center the legend box below the plot via anchor=north,at={(axis description cs:0.5,-0.18)},. The -0.18 should suffice for the y-offset due to the xlabel, at least it does in my case. I'd also recommend to use multiple legend columns with legend columns={..insert number here} then. –  henry Jun 24 at 14:01

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.