3

I am having a plot with legend entries. The entries are not really long, it would be nice to have them in a single row. The default behavior adds a line break after each entry. Furthermore, the are all centered, I would prefer left flushed.

I did not find the correct parameter for changing that. Anyone any suggestions or pointers fore me?

  • Are you using pgfplots? This is sort of impossible to answer without knowing how you created the plot and legend, so please add a minimal working example (MWE). – Torbjørn T. Mar 21 '14 at 22:22
  • I see from your other question (that I also commented on) that you are indeed using pgfplots. Still, my previous comment applies. – Torbjørn T. Mar 21 '14 at 22:27
  • Yes, sorry. I will add an MWE the next time. sry! – user1091534 Mar 21 '14 at 22:33
4

You can use the legend columns key (-1 makes all legends to go horizontally):

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\pgfplotsset{every axis legend/.append style={
at={(0.5,1.03)},
anchor=south}}
\begin{axis}[legend columns=-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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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