21

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?)

P. Fonseca
  • 6,665
  • 2
  • 28
  • 60

2 Answers2

34

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}]
MinHsuan Peng
  • 2,046
  • 15
  • 14
  • 12
    This construct for LegendLayout really needs to be inside the documentation. It is extremely useful – Jonie Jul 31 '13 at 01:07
4

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}].

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • 1
    try: LegendLayout -> (Grid[{Flatten@#}] &), that should do the trick (for the pure function that is) – Pinguin Dirk Jun 01 '13 at 09:07
  • @PinguinDirk Ah, it does. I should have thought about this :p – Kuba Jun 01 '13 at 09:13
  • 4
    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]]]. – rcollyer Jun 10 '13 at 14:14