6
$\begingroup$

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?

$\endgroup$
  • 2
    $\begingroup$ Perhaps the question title is not too well suited for those not familiar with the first part - consider rephrasing to help future visitors. $\endgroup$ – Yves Klett Sep 3 '12 at 14:50
  • $\begingroup$ @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? $\endgroup$ – Harald Sep 4 '12 at 5:46
  • $\begingroup$ 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. $\endgroup$ – Yves Klett Sep 4 '12 at 6:59
  • 1
    $\begingroup$ I agree. I changed it and I hope it is now more or less ok $\endgroup$ – Harald Sep 4 '12 at 7:32
7
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Verde: Thanks a lot!! $\endgroup$ – Harald Sep 3 '12 at 17:02
5
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Ajasja: Thanks a lot!! $\endgroup$ – Harald Sep 3 '12 at 17:01

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.