7

What I am doing wrong? I would like to get a header to the table and based on your code I tried this:

hdr = {{"Calculated Coordinates", SpanFromLeft}, {"No", "x", "y"}};
hdr1 = Grid[hdr, Frame -> All];

legendmarkers=Range@Length@data;
                    
legendlabels=Map[Style[AccountingForm[#, 10], FontSize -> 20, FontFamily -> "Calibri"] &, data, {-1}];
                    
styledheaders=Style[#,Bold,FontSize -> 22,FontFamily -> "Calibri"] & /@ {hdr1};
                    
legendGrd = Grid[Prepend[Transpose[Join[{legendmarkers}, 
Transpose[legendlabels]]], styledheaders], Frame -> All,
BaseStyle -> {FontSize -> 20, FontFamily -> "Calibri"},
FrameStyle -> GrayLevel[.9], Alignment -> {Center, Center},
Background -> {None, {GrayLevel[.5], {GrayLevel[.8]}}}]

The result is:

Legend

Calculated Coordinates should span all three columns, and No, x, and y should be the header of the corresponding columns.

What must I do to get this?

LCarvalho
  • 9,233
  • 4
  • 40
  • 96
Harald
  • 1,573
  • 1
  • 11
  • 15
  • 2
    Perhaps the question title is not too well suited for those not familiar with the first part - consider rephrasing to help future visitors. – Yves Klett Sep 03 '12 at 14:50
  • @Klett: Of course, I can do it. But don't you think, that the link to the first question of this topic will do it? – Harald Sep 04 '12 at 05:46
  • Not really - if you browse the questions, a meaningful, self-contained title is important. Having to retrace a question´s history to understand it is not beneficial. This question is about spanning table headings, not about a table in a legend. – Yves Klett Sep 04 '12 at 06:59
  • 1
    I agree. I changed it and I hope it is now more or less ok – Harald Sep 04 '12 at 07:32

2 Answers2

7

Another way:

(* The following command imports your data from an image, see 
   http://meta.mathematica.stackexchange.com/a/633/193 for an explanation *)

ToExpression@Uncompress@FromCharacterCode@Flatten@Import["http://tinyurl.com/cbr4wkf","Data"]

Now the code

sh = Style[#, Bold, FontSize -> 22, FontFamily -> "Calibri"] &; 
hdr = {{sh@"Calculated Coordinates", SpanFromLeft, SpanFromLeft}, sh /@ {"No", "x", "y"}};

leglbl = Map[Style[AccountingForm[#, 10]] &, data, {-1}];

legendGrd = Grid[
             Join[hdr, MapThread[Prepend, {leglbl, Range@Length@data}]], 
             BaseStyle  -> {FontSize -> 20, FontFamily -> "Calibri"}, Frame -> All, 
             FrameStyle -> GrayLevel[.9], Alignment -> {Center, Center}, 
             Background -> {None, {GrayLevel[.5], GrayLevel[.5], {GrayLevel[.8]}}}]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • Verde: Thanks a lot!! – Harald Sep 03 '12 at 17:02
  • To the future visitors who might face a problem while running the codes: for some unknown reasons, the Uncompress function might not work as expected. So you have to split the code in two parts. i.e. str = FromCharacterCode@Flatten@ImageData[Import@"the-encoded-address","Data"]; and then concatenate the string with one or maybe two zeros, like this: ToExpression@Uncompress[str<>"0"] – polfosol Sep 08 '21 at 06:58
5

Here is one way. The trick is making the header part of the data.

hdr = {{"Calculated Coordinates", SpanFromLeft, SpanFromLeft}, {"No", 
    "x", "y"}};
data = RandomReal[{-1, 1}, {10, 2}];
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 -> 22, 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]}}}]

Mathematica graphics

Ajasja
  • 13,634
  • 2
  • 46
  • 104