2
$\begingroup$

Using Jens's code:

data = Map[AccountingForm, gedreht , {-1}];
result = Framed@
   Row[{end, 
     Grid[Transpose[{Range@Length@data, 
         Map[AccountingForm, data, {2}]}] /. {x_, {y__}} -> {x, y}, 
      Frame -> All]}];
hdr = {{"Berechnete Koordinaten", SpanFromLeft, SpanFromLeft}, {"Nr.",
     "x", "y"}};
legendmarkers = Range@Length@data;
legendlabels = 
  Map[Style[AccountingForm[#, 10], FontSize -> 20, 
     FontFamily -> "Calibri"] &, data, {-1}];
hdr[[2]] = 
  Style[#, Bold, FontSize -> 22, FontFamily -> "Calibri"] & /@ 
   hdr[[2]];
hdr[[1, 1]] = 
  Style[hdr[[1, 1]], Bold, FontSize -> 26, FontFamily -> "Calibri"];
legendGrd = 
  Grid[hdr~Join~
    Transpose[Join[{legendmarkers}, Transpose[legendlabels]]], 
   Frame -> All, 
   BaseStyle -> {FontSize -> 20, FontFamily -> "Calibri"}, 
   FrameStyle -> GrayLevel[.9], Alignment -> {Center, Center}, 
   Background -> {None, {GrayLevel[.5], 
      GrayLevel[.5], {GrayLevel[.8]}}}];
plan = Panel@Row[{end, legendGrd}, Spacer[5]]

I sometimes get pretty huge tables for the legend of a figure:

Table

How can I split this table in subtables of, say, 20 lines and to arrange them horizontally?

Thanks a lot!!

$\endgroup$
4
  • $\begingroup$ partition this: Transpose[Join[{legendmarkers}, Transpose[legendlabels]]] into the size you want. You will have to remake the header to match the dimensions. $\endgroup$ Commented Nov 3, 2012 at 22:13
  • $\begingroup$ It appears that neither gedreht nor end are defined. I cannot find them in Jens post either. $\endgroup$
    – DavidC
    Commented Nov 3, 2012 at 22:30
  • $\begingroup$ you are right. "end" is defined as: end = Overlay[{Show[g, plot1a], legendMaker[textLabels, PlotStyle -> manualPlotstyles, PlotMarkers -> manualMarkers, Background -> Directive[Opacity[.5], Black], "LegendLineAspectRatio" -> .3, "LegendGridOptions" -> {Alignment -> Left, Spacings -> {0.7, .25}, Background -> {{GrayLevel[.8], None}, None}}]}, Alignment -> {-.55, -.620}]; and "gedreht" is defined as r = RotationTransform[grad, {x1, y1}]; r[ungedreht]; gedreht = r[ungedreht]; within a larger code. I just used Jen's code as a part of my code $\endgroup$
    – Harald
    Commented Nov 3, 2012 at 23:41
  • $\begingroup$ Similar question: [mathematica.stackexchange.com/q/11849/3056] $\endgroup$
    – kirma
    Commented Nov 4, 2012 at 9:53

1 Answer 1

5
$\begingroup$
ClearAll[divideTblF, gridF];
(* a function to re-arrange an n-by-m list into an r-by-(m n / r) list:   *)
divideTblF[table_List, rows_Integer] :=  Module[{dims = Dimensions[table], r},
r = Min[rows, First@dims];
 Flatten /@ Transpose[Partition[table, r, r, 1, {ConstantArray[Null, Last@dims]}]]];
(* grid with legend and column headers added to the input table: *)
gridF[x_, legendheader_, colheaders_, opts : OptionsPattern[]] :=
Grid[Join[{{legendheader, SpanFromLeft},
  colheaders[[Mod[Range[Last@Dimensions[x]], Length[colheaders], 1]]]}, x],
   FilterRules[{opts}, Options[Grid]]];

Update: a more elegant alternative to Flatten/@Transpose[...] is to use Join[##,2]&@@(...):

 divideTblF2[table_List, rows_Integer] := Module[{dims = Dimensions[table], 
       r = Min[rows, First@Dimensions[table]] },
    Join[##, 2] & @@ (Partition[table, r, r, 1, {ConstantArray[Null, Last@dims]}])]

Examples:

dataTable = {{11, 12, 13}, {21, 22, 23}, {31, 32, 33}, {41, 42, 43},
  {51, 52, 53}, {61, 62, 63}};
dataTable // Grid

enter image description here

Column[#, Spacer[5], Frame -> All] &@
  (gridF[divideTblF[dataTable, #], "legend", {"col1", "col2", "col3"},
      Dividers -> All] & /@ {6, 5, 4, 3, 2})

enter image description here

$\endgroup$
3
  • $\begingroup$ thanks a lot, I will have a deeper look at your code tomorrow morning, now (at 1 a.m.) I should finish my work... $\endgroup$
    – Harald
    Commented Nov 3, 2012 at 23:59
  • $\begingroup$ thanks a lot for your answer and for your code. It is of great help for me!!! $\endgroup$
    – Harald
    Commented Nov 4, 2012 at 11:39
  • $\begingroup$ @Harald, my pleasure. Glad it was useful for you. $\endgroup$
    – kglr
    Commented Nov 4, 2012 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.