pgfplots: How to align legend to same width as plot?pgfplots: How to control and align legend items precisely above each other?plotting two time series with boundsGrouped bar chartHow do i get the x axis on top but keep a line on the bottomHow to prevent rounded and duplicated tick labels in pgfplots with fixed precision?How to increase legend lines lengths in PGFplotsHow to hide empty (value 0) ybars with pgfplots?Show mark labels near marks and not centered in ybar interaval graphLine up nested tikz enviroments or how to get rid of thempgfplots: percentage in matrix plotCenter the axes in the coordinate origin
Open a doc from terminal, but not by its name
Why does a simple loop result in ASYNC_NETWORK_IO waits?
This is why we puzzle
How do you make your own symbol when Detexify fails?
Which was the first story featuring espers?
Why should universal income be universal?
Shouldn’t conservatives embrace universal basic income?
Is there a nicer/politer/more positive alternative for "negates"?
Multiplicative persistence
Is this toilet slogan correct usage of the English language?
Giving feedback to someone without sounding prejudiced
Do we have to expect a queue for the shuttle from Watford Junction to Harry Potter Studio?
Why is the "ls" command showing permissions of files in a FAT32 partition?
What (the heck) is a Super Worm Equinox Moon?
awk assign to multiple variables at once
How to create a paid keyvalue store
What to do when eye contact makes your coworker uncomfortable?
It grows, but water kills it
What is going on with gets(stdin) on the site coderbyte?
15% tax on $7.5k earnings. Is that right?
Does the Linux kernel need a file system to run?
Why does int i = 10; i / 0; compile, but 5 / 0 gives CS0020 - Division by constant zero?
What is the duration of the spell Creation when used to create non-precious metals?
How can I write humor as character trait?
pgfplots: How to align legend to same width as plot?
pgfplots: How to control and align legend items precisely above each other?plotting two time series with boundsGrouped bar chartHow do i get the x axis on top but keep a line on the bottomHow to prevent rounded and duplicated tick labels in pgfplots with fixed precision?How to increase legend lines lengths in PGFplotsHow to hide empty (value 0) ybars with pgfplots?Show mark labels near marks and not centered in ybar interaval graphLine up nested tikz enviroments or how to get rid of thempgfplots: percentage in matrix plotCenter the axes in the coordinate origin
The user marmot has posted a nice approach to put a multigraph legend below a diagram.
Minimum Working Example (MWE):
documentclass[border=5mm]standalone
usepackagepgfplots
usetikzlibrarypositioning
pgfplotssetcompat=newest, scale only axis
begindocument
pgfplotssetsuperb legend/.style=legend style = draw=none,
legend columns = 3,
/tikz/every even column/.append style = column sep=0.5cm,
text width=7em,
/tikz/every odd column/.append style = column sep=0.15cm,
text width=7em,
begintikzpicture
beginscope[local bounding box=plots]
beginaxis[
axis y line* = left,
legend to name = legA,
superb legend
]%
addplot coordinates (0,0) (1,1);
addplot coordinates (1,0) (0,1);
addplot coordinates (0,1) (1,1);
legendGraph 1, Graph 2, Graph 3;
endaxis%
%
beginaxis[
axis x line = none,
axis y line* = right,
legend to name = legB,
superb legend
]%
addplot coordinates (0,1) (1,0);
addplot coordinates (0,0.5) (1,0.5);
addplot coordinates (0,0.15) (1,0.15);
legendGraphinggraph~4, Graphinggraph~5, Graphinggraph~6;
endaxis%
%
beginaxis[
axis x line = none,
axis y line* = right,
legend to name = legC,
superb legend
]%
pgfplotsset%
%
every outer y axis line/.style = xshift=2cm,
every tick/.style = xshift=2cm,
every y tick label/.style = xshift=2cm,
%
addplot coordinates (0.5,0) (0.5,1);
addplot coordinates (0.6,0) (0.6,1);
addplot coordinates (0.7,0) (0.7,1);
legendGraphgraph 7, Graphgraph 8, Graphgraph 9;
endaxis%
endscope
node[below=3.5em of plots.south] (legA) reflegA;
node[below=-0.5em of legA] (legB) reflegB;
node[below=-0.5em of legB] (legC) reflegC;
draw (legA.north west) rectangle (legC.south east);
endtikzpicture
enddocument
Screenshot of the result:

Description of the issue:
- Would it be possible to adjust the width of the plot to the width of the legend box (see upper screenshot with red markings)?
Or, alternatively:
- Adjust the width of the legend box to the width of the plot?
How can I solve that nicely without playing around with the legend items text width? Maybe we can create some global variable to specify the widths of legend and plot together?
tikz-pgf pgfplots width legend adjustwidth
add a comment |
The user marmot has posted a nice approach to put a multigraph legend below a diagram.
Minimum Working Example (MWE):
documentclass[border=5mm]standalone
usepackagepgfplots
usetikzlibrarypositioning
pgfplotssetcompat=newest, scale only axis
begindocument
pgfplotssetsuperb legend/.style=legend style = draw=none,
legend columns = 3,
/tikz/every even column/.append style = column sep=0.5cm,
text width=7em,
/tikz/every odd column/.append style = column sep=0.15cm,
text width=7em,
begintikzpicture
beginscope[local bounding box=plots]
beginaxis[
axis y line* = left,
legend to name = legA,
superb legend
]%
addplot coordinates (0,0) (1,1);
addplot coordinates (1,0) (0,1);
addplot coordinates (0,1) (1,1);
legendGraph 1, Graph 2, Graph 3;
endaxis%
%
beginaxis[
axis x line = none,
axis y line* = right,
legend to name = legB,
superb legend
]%
addplot coordinates (0,1) (1,0);
addplot coordinates (0,0.5) (1,0.5);
addplot coordinates (0,0.15) (1,0.15);
legendGraphinggraph~4, Graphinggraph~5, Graphinggraph~6;
endaxis%
%
beginaxis[
axis x line = none,
axis y line* = right,
legend to name = legC,
superb legend
]%
pgfplotsset%
%
every outer y axis line/.style = xshift=2cm,
every tick/.style = xshift=2cm,
every y tick label/.style = xshift=2cm,
%
addplot coordinates (0.5,0) (0.5,1);
addplot coordinates (0.6,0) (0.6,1);
addplot coordinates (0.7,0) (0.7,1);
legendGraphgraph 7, Graphgraph 8, Graphgraph 9;
endaxis%
endscope
node[below=3.5em of plots.south] (legA) reflegA;
node[below=-0.5em of legA] (legB) reflegB;
node[below=-0.5em of legB] (legC) reflegC;
draw (legA.north west) rectangle (legC.south east);
endtikzpicture
enddocument
Screenshot of the result:

Description of the issue:
- Would it be possible to adjust the width of the plot to the width of the legend box (see upper screenshot with red markings)?
Or, alternatively:
- Adjust the width of the legend box to the width of the plot?
How can I solve that nicely without playing around with the legend items text width? Maybe we can create some global variable to specify the widths of legend and plot together?
tikz-pgf pgfplots width legend adjustwidth
add a comment |
The user marmot has posted a nice approach to put a multigraph legend below a diagram.
Minimum Working Example (MWE):
documentclass[border=5mm]standalone
usepackagepgfplots
usetikzlibrarypositioning
pgfplotssetcompat=newest, scale only axis
begindocument
pgfplotssetsuperb legend/.style=legend style = draw=none,
legend columns = 3,
/tikz/every even column/.append style = column sep=0.5cm,
text width=7em,
/tikz/every odd column/.append style = column sep=0.15cm,
text width=7em,
begintikzpicture
beginscope[local bounding box=plots]
beginaxis[
axis y line* = left,
legend to name = legA,
superb legend
]%
addplot coordinates (0,0) (1,1);
addplot coordinates (1,0) (0,1);
addplot coordinates (0,1) (1,1);
legendGraph 1, Graph 2, Graph 3;
endaxis%
%
beginaxis[
axis x line = none,
axis y line* = right,
legend to name = legB,
superb legend
]%
addplot coordinates (0,1) (1,0);
addplot coordinates (0,0.5) (1,0.5);
addplot coordinates (0,0.15) (1,0.15);
legendGraphinggraph~4, Graphinggraph~5, Graphinggraph~6;
endaxis%
%
beginaxis[
axis x line = none,
axis y line* = right,
legend to name = legC,
superb legend
]%
pgfplotsset%
%
every outer y axis line/.style = xshift=2cm,
every tick/.style = xshift=2cm,
every y tick label/.style = xshift=2cm,
%
addplot coordinates (0.5,0) (0.5,1);
addplot coordinates (0.6,0) (0.6,1);
addplot coordinates (0.7,0) (0.7,1);
legendGraphgraph 7, Graphgraph 8, Graphgraph 9;
endaxis%
endscope
node[below=3.5em of plots.south] (legA) reflegA;
node[below=-0.5em of legA] (legB) reflegB;
node[below=-0.5em of legB] (legC) reflegC;
draw (legA.north west) rectangle (legC.south east);
endtikzpicture
enddocument
Screenshot of the result:

Description of the issue:
- Would it be possible to adjust the width of the plot to the width of the legend box (see upper screenshot with red markings)?
Or, alternatively:
- Adjust the width of the legend box to the width of the plot?
How can I solve that nicely without playing around with the legend items text width? Maybe we can create some global variable to specify the widths of legend and plot together?
tikz-pgf pgfplots width legend adjustwidth
The user marmot has posted a nice approach to put a multigraph legend below a diagram.
Minimum Working Example (MWE):
documentclass[border=5mm]standalone
usepackagepgfplots
usetikzlibrarypositioning
pgfplotssetcompat=newest, scale only axis
begindocument
pgfplotssetsuperb legend/.style=legend style = draw=none,
legend columns = 3,
/tikz/every even column/.append style = column sep=0.5cm,
text width=7em,
/tikz/every odd column/.append style = column sep=0.15cm,
text width=7em,
begintikzpicture
beginscope[local bounding box=plots]
beginaxis[
axis y line* = left,
legend to name = legA,
superb legend
]%
addplot coordinates (0,0) (1,1);
addplot coordinates (1,0) (0,1);
addplot coordinates (0,1) (1,1);
legendGraph 1, Graph 2, Graph 3;
endaxis%
%
beginaxis[
axis x line = none,
axis y line* = right,
legend to name = legB,
superb legend
]%
addplot coordinates (0,1) (1,0);
addplot coordinates (0,0.5) (1,0.5);
addplot coordinates (0,0.15) (1,0.15);
legendGraphinggraph~4, Graphinggraph~5, Graphinggraph~6;
endaxis%
%
beginaxis[
axis x line = none,
axis y line* = right,
legend to name = legC,
superb legend
]%
pgfplotsset%
%
every outer y axis line/.style = xshift=2cm,
every tick/.style = xshift=2cm,
every y tick label/.style = xshift=2cm,
%
addplot coordinates (0.5,0) (0.5,1);
addplot coordinates (0.6,0) (0.6,1);
addplot coordinates (0.7,0) (0.7,1);
legendGraphgraph 7, Graphgraph 8, Graphgraph 9;
endaxis%
endscope
node[below=3.5em of plots.south] (legA) reflegA;
node[below=-0.5em of legA] (legB) reflegB;
node[below=-0.5em of legB] (legC) reflegC;
draw (legA.north west) rectangle (legC.south east);
endtikzpicture
enddocument
Screenshot of the result:

Description of the issue:
- Would it be possible to adjust the width of the plot to the width of the legend box (see upper screenshot with red markings)?
Or, alternatively:
- Adjust the width of the legend box to the width of the plot?
How can I solve that nicely without playing around with the legend items text width? Maybe we can create some global variable to specify the widths of legend and plot together?
tikz-pgf pgfplots width legend adjustwidth
tikz-pgf pgfplots width legend adjustwidth
asked 1 min ago
DaveDave
905619
905619
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f480910%2fpgfplots-how-to-align-legend-to-same-width-as-plot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f480910%2fpgfplots-how-to-align-legend-to-same-width-as-plot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown