16
$\begingroup$

When using LegendLayout->"Row", with a lengthy row, I get line breaks. This would seemed logic if it was confined by another structure. But if happens even when there's no "confinement":

LineLegend[{Blue, Orange, Green}, {"this is a big test", 
  "this is a big test", "this is a big test"}, LegendLayout -> "Row"]

enter image description here

How can I change the ItemSize/ImageSize of the Legend?

(should this behavior be reported?)

$\endgroup$
24
$\begingroup$

Tell it that you really want n rows by {"Row", n}, for example:

LineLegend[{Blue, Orange, Green}, {"this is a big test", 
"this is a big test", "this is a big test"}, 
LegendLayout -> {"Row", 1}]
$\endgroup$
  • 8
    $\begingroup$ This construct for LegendLayout really needs to be inside the documentation. It is extremely useful $\endgroup$ – Jonie Jul 31 '13 at 1:07
4
$\begingroup$

To avoid line breaks You can use Grid insted (more here):

f[x_] := Grid[{Flatten@x}];

LineLegend[{Blue, Orange, Green}, {"this is a big test", 
 "this is a big test", "this is a big test"}, LegendLayout -> f]

Edit

Strange thing that I can not put pure function to LegendLayout option :/ If You don't want to define f outside, use: LegendLayout->Function[{x}, Grid@{Flatten@x}].

$\endgroup$
  • 1
    $\begingroup$ try: LegendLayout -> (Grid[{Flatten@#}] &), that should do the trick (for the pure function that is) $\endgroup$ – Pinguin Dirk Jun 1 '13 at 9:07
  • $\begingroup$ @PinguinDirk Ah, it does. I should have thought about this :p $\endgroup$ – Kuba Jun 1 '13 at 9:13
  • 3
    $\begingroup$ The reason you need the parentheses is & has a lower precedence than ->. If you run FullForm[q -> #&] you get Function[Rule[q, Slot[1]]], but add parentheses: FullForm[q -> (#&)] you get, Rule[q, Function[Slot[1]]]. $\endgroup$ – rcollyer Jun 10 '13 at 14:14

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.