I have a question regarding the alignment of the content of the legend. The default option is centering, but I want to have it aligned to the left. How can I change this?

\begin{axis}[xbar stacked,
legend style={legend columns=1,at={(axis cs:350, 0.4)},anchor=south west,draw=none},
axis y line*=left,
axis x line*=bottom,
tick label style={font=\footnotesize},
legend style={font=\footnotesize},
label style={font=\footnotesize, text left},
bar width=3mm,
xlabel={Time in seconds},
ylabel={Pool sizes},
area legend,
enlarge y limits={abs=0.625},
\addplot[time RR,pattern=horizontal lines, pattern color = time RR] coordinates
% Time RR
{(0.00,0) (2.44,1) (8.48,2) (16.16,3) (22.26,4) (37.03, 5) (49.70,6) (68.45,7)};
\addplot[time Multi-Thread,pattern=north east lines, pattern color = time Multi-Thread] coordinates
% Time LS/SA
{(231.12,0) (223.00,1) (220.93,2) (219.75, 3) (222.66,4) (221.61,5) (222.67,6) (244.95,7)};
\addplot[time POOL,pattern=vertical lines, pattern color = time POOL] coordinates
% Time POOL
{(0.00, 0) (10.01,1) (25.65,2) (41.51,3) (57.02,4) (87.82,5) (121.88,6) (160.44,7)};
\addplot[Overhead time,pattern=grid, pattern color = Overhead time] coordinates
% Else
{(0.27,0) (0.15,1) (0.14,2) (0.14,3) (0.15,4) (0.15,5) (0.15,6) (0.17,7)};
\legend{time RR,time Multi-Thread,time POOL,Overhead time}
\caption{Analysis of computational time on the sizes of $POOL$}
\label{fig: Time division}

enter image description here

  • You might want to post this question on the TeX - LaTeX site where the latex experts are.
    – Pang
    Jun 30 '16 at 2:00
  • Welcome to TeX.SE! Please expand you code sniped to complete document which can be copied to our computers and compile. Probably you need add align=left to legend style.
    – Zarko
    Jun 30 '16 at 10:15

Answer : add legend cell align={left} to the options of your axis environment:

   ... ,
legend cell align={left},

User code

The following code is a minimal working example:


    title=Left-align Legend with pgfplots,
    legend cell align={left}, % The command for legend alignment
    legend entries={$y = x^2$,Tangent at $x=1$}



which produces the following output when compiled with pdflatex (and all the required packages):

Minimal working example

  • Welcome to TeX.SX!! Rather than giving code fragments it is better to post a full minimal working example. Currently we have to guess what you packages etc you are using, which makes it is difficult reconstruct, and hence fix. A MWE should start with a \documentclass command, have a minimal preamble and then \begin{document}...\end{document}. The code should compile and be as small as possible to demonstrate your problem. This makes it much easier for people to help you --- and much more likely that they will!
    – user30471
    Jul 28 '16 at 21:58

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.