2
$\begingroup$

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)

$\endgroup$
2
$\begingroup$

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.

$\endgroup$
7
$\begingroup$

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

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Delphine Mar 21 '16 at 16:15
  • 1
    $\begingroup$ /@ is simply Map. You can usually figure them out by entering ? /@ or something like FullForm[f /@ g]. $\endgroup$ – Martin Ender Mar 21 '16 at 16:16
  • $\begingroup$ Thank you! Edited to add that info. $\endgroup$ – Delphine Mar 21 '16 at 16:18
  • 1
    $\begingroup$ @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: mathematica.stackexchange.com/questions/18393/… $\endgroup$ – Jason B. Mar 21 '16 at 16:25
  • $\begingroup$ @JasonB Oh, that's true. It seems that the only thing that still works on those is F1. $\endgroup$ – Martin Ender Mar 21 '16 at 16:29

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.