7
$\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$
4
  • 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, 2012 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, 2012 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, 2012 at 6:59
  • 1
    $\begingroup$ I agree. I changed it and I hope it is now more or less ok $\endgroup$
    – Harald
    Sep 4, 2012 at 7:32

2 Answers 2

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$
2
  • $\begingroup$ Verde: Thanks a lot!! $\endgroup$
    – Harald
    Sep 3, 2012 at 17:02
  • $\begingroup$ 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"] $\endgroup$
    – polfosol
    Sep 8, 2021 at 6:58
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$
1
  • $\begingroup$ Ajasja: Thanks a lot!! $\endgroup$
    – Harald
    Sep 3, 2012 at 17:01

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.