From a previous question and with the help of kglr a grid containing a data matrix with column labels was properly formatted and created Controlling label alignment/spacing in large grids

Having this grid in hand, I would like to generate a new grid that includes row labels, but have discovered I still do not fully understand how to successfully use the Part, Style and Join Functions in this context. I've tried to follow several answers in several previous questions regarding grid labeling, but can not seem to create the proper syntax to add the newly styled row labels to the previous grid. Note that the fonts in the original grid are not italicized, whereas those in the labels are using FontSlant->Italic. Note also that the column spacing and the rotated column labels of the original grid need to be retained in the final grid.

For purposes of example and to match the grid in the previous post I use the following set of row labels:

 mspecies = {"                   ", "Synanceia verrucosa", "Pterois volitans", "Pterois miles", 
 "Helicolenus avius", "Helicolenus hilgendorfi","Sebastes aleutianus", "Sebastes fasciatus", 
 "Sebastes koreanus","Sebastes trivittatus"}

That I have styled using:

 mspecies2 = 
   Style[mspecies, FontFamily -> "Helvetica", FontSize -> 8, 
   FontWeight -> Bold, FontSlant -> Italic]

which I would like to appear as row labels in the new grid.

Is there a way to effectively Preappend this list of row labels suitably formatted to the original grid to form a new grid retaining both the content and formatting of the original data and labels but including the new properly styled row labels?


1 Answer 1


You can map Style on elements of mspecies:

mspecies2 = Style[#, FontFamily -> "Helvetica", FontSize -> 8, 
    FontWeight -> Bold, FontSlant -> Italic] & /@ mspecies;

Use the method in the linked q/a to get a 9X20 grid with rotated column headers:

n = 20;
result = Join[ConstantArray["A", {5, n}], ConstantArray["T", {4, n}]];
columnlabels = Range[Last[Dimensions[result]]];
newcolumnlabels = Rotate[StringTake["00000" <> ToString[#], -5], \[Pi]/2] & /@ 

Prepend each row with its styled row header:

datawithheaders = MapThread[Prepend, {Prepend[result, newcolumnlabels], mspecies2}];

  Frame -> All, Alignment -> {Center, Center}], FontSize -> 8, 
 LineBreakWithin -> False]

enter image description here

Use Alignment -> {Center, Center, {1 -> Left}} to get

`enter image description here

  • $\begingroup$ kglr, you make it look too easy. However, one small point. Note that the alignment of the row labels has been centered, where left is desired for the row labels and centered for the column labels. If one makes the Alignment {Left, Center} to left align the row labels one also aligns the columns left as well, which is undesirable. Alignment {Center,Left} seems to have no effect. Not sure how to correct this. $\endgroup$ Commented May 9, 2020 at 4:55
  • 1
    $\begingroup$ @StuartPoss, please see the update. $\endgroup$
    – kglr
    Commented May 9, 2020 at 5:21

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.