2

How can I style headers in a grid to be in Arial, 20pt?

g = Plot[x^2, {x, 0, 2}];
headers={"A", "B", "C"};
Grid[Prepend[{{g, g, g}}, headers]]

Grid of plots with unformatted headers

(I decided to post this question/answer because I keep stumbling onto this. I know the answer is somewhere in some question but always have a hard time finding the related question)

Delphine
  • 235
  • 1
  • 9

2 Answers2

7

Using the Style function with Slot (#), Function (&) and Map (/@)

headers = Style[#, {FontFamily -> "Arial", FontSize -> 20}] & /@ {"A", "B", "C"}
Grid[Prepend[{{g, g, g}}, headers]]

enter image description here

MarcoB
  • 67,153
  • 18
  • 91
  • 189
Delphine
  • 235
  • 1
  • 9
  • I'm not entirely familiar with the special characters in Mathematica. I just discovered the Slot, could someone point me to the names of the other two? – Delphine Mar 21 '16 at 16:15
  • 1
    /@ is simply Map. You can usually figure them out by entering ? /@ or something like FullForm[f /@ g]. – Martin Ender Mar 21 '16 at 16:16
  • Thank you! Edited to add that info. – Delphine Mar 21 '16 at 16:18
  • 1
    @MartinBüttner - but the one that drove me up a wall was that you can't use the question mark on any of these: {@, @@, @@@}. @Delphine - see this post: http://mathematica.stackexchange.com/questions/18393/what-are-the-most-common-pitfalls-awaiting-new-users/25616#25616 – Jason B. Mar 21 '16 at 16:25
  • @JasonB Oh, that's true. It seems that the only thing that still works on those is F1. – Martin Ender Mar 21 '16 at 16:29
3

With ItemStyle option of Grid.

Grid[Prepend[{{g, g, g}}, headers],
 ItemStyle -> {Automatic, {1 -> {FontFamily -> "Arial", FontSize -> 20}}}]

enter image description here

This ItemStyle specification says use Automatic styling for the columns. Use Arial 20pt for row 1.

Hope this helps.

Edmund
  • 42,267
  • 3
  • 51
  • 143