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 Answers 2

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

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.