# Merging (Joining) Formatted Row Labels to an Existing Styled and Formatted Grid

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?

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] & /@
columnlabels;


Prepend each row with its styled row header:

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

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


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

`

• 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. May 9, 2020 at 4:55
• @StuartPoss, please see the update.
– kglr
May 9, 2020 at 5:21