Aligning legends in multiple columns with pgfplots
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
How can you align the text inside labels with pgfplots? In the example below, I would like to align both the k's and the m's.
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentry$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentry$k = 2$, $m = 3$
endaxis
endtikzpicture
enddocument
pgfplots
add a comment |Â
up vote
3
down vote
favorite
How can you align the text inside labels with pgfplots? In the example below, I would like to align both the k's and the m's.
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentry$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentry$k = 2$, $m = 3$
endaxis
endtikzpicture
enddocument
pgfplots
1
have a look at tex.stackexchange.com/a/440121/36296
– samcarter
Aug 15 at 12:35
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
How can you align the text inside labels with pgfplots? In the example below, I would like to align both the k's and the m's.
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentry$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentry$k = 2$, $m = 3$
endaxis
endtikzpicture
enddocument
pgfplots
How can you align the text inside labels with pgfplots? In the example below, I would like to align both the k's and the m's.
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentry$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentry$k = 2$, $m = 3$
endaxis
endtikzpicture
enddocument
pgfplots
asked Aug 15 at 12:11


Ema
183
183
1
have a look at tex.stackexchange.com/a/440121/36296
– samcarter
Aug 15 at 12:35
add a comment |Â
1
have a look at tex.stackexchange.com/a/440121/36296
– samcarter
Aug 15 at 12:35
1
1
have a look at tex.stackexchange.com/a/440121/36296
– samcarter
Aug 15 at 12:35
have a look at tex.stackexchange.com/a/440121/36296
– samcarter
Aug 15 at 12:35
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
4
down vote
accepted
I don't think that there is general way, at the end you have two more or less independant nodes. How at best to "synchronize" their content depends a lot on the concrete case. And almost everything that works is ok.
In your example I would probably use eqparbox:
documentclass[preview]standalone
usepackagepgfplots
usepackageeqparbox
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
%legend columns=2
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentryeqmakebox[m1][l]$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentryeqmakebox[m1][l]$k = 2$, $m = 3$
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
3
down vote
Quick hack:
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentry$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentry$k = 2$,phantom0 $m = 3$
endaxis
endtikzpicture
enddocument
Yes, I could also do it by inserting ahfill
with the appropriate length as well, but I was wondering if there was a general way.
– Ema
Aug 15 at 12:32
add a comment |Â
up vote
1
down vote
This solution is similar to the linked one except that I use an array instead of align. Note that the array is actually overlaid over a bunch of strut
s. Not sure why one needs to tweak arraystretch
for this.
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addplot[red, domain=1:4, samples=4] 2*x + 3;
legendsmashdefarraystretch1.15% align tabular to struts
$beginarray[t]@k=nulll@$ $m=nulll@
10,&-5\
2,&3
endarray$strut,strut
endaxis
endtikzpicture
enddocument
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
I don't think that there is general way, at the end you have two more or less independant nodes. How at best to "synchronize" their content depends a lot on the concrete case. And almost everything that works is ok.
In your example I would probably use eqparbox:
documentclass[preview]standalone
usepackagepgfplots
usepackageeqparbox
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
%legend columns=2
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentryeqmakebox[m1][l]$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentryeqmakebox[m1][l]$k = 2$, $m = 3$
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
4
down vote
accepted
I don't think that there is general way, at the end you have two more or less independant nodes. How at best to "synchronize" their content depends a lot on the concrete case. And almost everything that works is ok.
In your example I would probably use eqparbox:
documentclass[preview]standalone
usepackagepgfplots
usepackageeqparbox
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
%legend columns=2
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentryeqmakebox[m1][l]$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentryeqmakebox[m1][l]$k = 2$, $m = 3$
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
I don't think that there is general way, at the end you have two more or less independant nodes. How at best to "synchronize" their content depends a lot on the concrete case. And almost everything that works is ok.
In your example I would probably use eqparbox:
documentclass[preview]standalone
usepackagepgfplots
usepackageeqparbox
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
%legend columns=2
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentryeqmakebox[m1][l]$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentryeqmakebox[m1][l]$k = 2$, $m = 3$
endaxis
endtikzpicture
enddocument
I don't think that there is general way, at the end you have two more or less independant nodes. How at best to "synchronize" their content depends a lot on the concrete case. And almost everything that works is ok.
In your example I would probably use eqparbox:
documentclass[preview]standalone
usepackagepgfplots
usepackageeqparbox
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
%legend columns=2
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentryeqmakebox[m1][l]$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentryeqmakebox[m1][l]$k = 2$, $m = 3$
endaxis
endtikzpicture
enddocument
answered Aug 15 at 12:58


Ulrike Fischer
177k7281649
177k7281649
add a comment |Â
add a comment |Â
up vote
3
down vote
Quick hack:
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentry$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentry$k = 2$,phantom0 $m = 3$
endaxis
endtikzpicture
enddocument
Yes, I could also do it by inserting ahfill
with the appropriate length as well, but I was wondering if there was a general way.
– Ema
Aug 15 at 12:32
add a comment |Â
up vote
3
down vote
Quick hack:
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentry$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentry$k = 2$,phantom0 $m = 3$
endaxis
endtikzpicture
enddocument
Yes, I could also do it by inserting ahfill
with the appropriate length as well, but I was wondering if there was a general way.
– Ema
Aug 15 at 12:32
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Quick hack:
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentry$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentry$k = 2$,phantom0 $m = 3$
endaxis
endtikzpicture
enddocument
Quick hack:
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addlegendentry$k = 10$, $m = -5$
addplot[red, domain=1:4, samples=4] 2*x + 3;
addlegendentry$k = 2$,phantom0 $m = 3$
endaxis
endtikzpicture
enddocument
answered Aug 15 at 12:21


samcarter
74k784238
74k784238
Yes, I could also do it by inserting ahfill
with the appropriate length as well, but I was wondering if there was a general way.
– Ema
Aug 15 at 12:32
add a comment |Â
Yes, I could also do it by inserting ahfill
with the appropriate length as well, but I was wondering if there was a general way.
– Ema
Aug 15 at 12:32
Yes, I could also do it by inserting a
hfill
with the appropriate length as well, but I was wondering if there was a general way.– Ema
Aug 15 at 12:32
Yes, I could also do it by inserting a
hfill
with the appropriate length as well, but I was wondering if there was a general way.– Ema
Aug 15 at 12:32
add a comment |Â
up vote
1
down vote
This solution is similar to the linked one except that I use an array instead of align. Note that the array is actually overlaid over a bunch of strut
s. Not sure why one needs to tweak arraystretch
for this.
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addplot[red, domain=1:4, samples=4] 2*x + 3;
legendsmashdefarraystretch1.15% align tabular to struts
$beginarray[t]@k=nulll@$ $m=nulll@
10,&-5\
2,&3
endarray$strut,strut
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
1
down vote
This solution is similar to the linked one except that I use an array instead of align. Note that the array is actually overlaid over a bunch of strut
s. Not sure why one needs to tweak arraystretch
for this.
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addplot[red, domain=1:4, samples=4] 2*x + 3;
legendsmashdefarraystretch1.15% align tabular to struts
$beginarray[t]@k=nulll@$ $m=nulll@
10,&-5\
2,&3
endarray$strut,strut
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
1
down vote
up vote
1
down vote
This solution is similar to the linked one except that I use an array instead of align. Note that the array is actually overlaid over a bunch of strut
s. Not sure why one needs to tweak arraystretch
for this.
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addplot[red, domain=1:4, samples=4] 2*x + 3;
legendsmashdefarraystretch1.15% align tabular to struts
$beginarray[t]@k=nulll@$ $m=nulll@
10,&-5\
2,&3
endarray$strut,strut
endaxis
endtikzpicture
enddocument
This solution is similar to the linked one except that I use an array instead of align. Note that the array is actually overlaid over a bunch of strut
s. Not sure why one needs to tweak arraystretch
for this.
documentclass[preview]standalone
usepackagepgfplots
begindocument
begintikzpicture
beginaxis[
title=$y=kx+m$,
ylabel=$y$,
xlabel=$x$,
legend cell align=left,
]
addplot[blue, domain=1:4, samples=4] 10*x - 5;
addplot[red, domain=1:4, samples=4] 2*x + 3;
legendsmashdefarraystretch1.15% align tabular to struts
$beginarray[t]@k=nulll@$ $m=nulll@
10,&-5\
2,&3
endarray$strut,strut
endaxis
endtikzpicture
enddocument
edited Aug 15 at 14:41
answered Aug 15 at 14:02


John Kormylo
40.5k12363
40.5k12363
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f446131%2faligning-legends-in-multiple-columns-with-pgfplots%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
have a look at tex.stackexchange.com/a/440121/36296
– samcarter
Aug 15 at 12:35