How can I define a style with FontSize from Section and CellFrame from Program?



I must have read fontstyle instead of fontsize in your question. Therefore, the approach below shows how to use the complete style of Section with the frame of Program. To achieve what you want, just create a new style and copy any style properties (e.g. FontSize and CellFrame) from any existing style with the method I explain below.

Sidenote: To inherit a style, it's not necessary to copy anything. You can just use

Cell[StyleData["MySec",StyleDefinitions->StyleData["Section"]], ...]

as explained by Mike in the comments.

Original answer

Go to Format -> Edit Stylesheet... and click on the Default.nb link in the upper left corner. There you go to Style for Title and Section Cells and click on the Section. Press Ctrl+Shift+E or go to Cell -> Show Expression and copy the whole Cell expression. Afterwards you can close the cell expression with the same shortcut again.

Note: When you only want to reuse an existing style, you can just copy the cell without showing the cell expression. I only explained it because we need it in the following and show, what you really copy.

Now you go into your empty local stylesheet and create a new style by entering a name into the text box on top of the page. Click on your created style cell and open it with Ctrl+Shift+E. Paste the contents of the section definition there

enter image description here

Be carefull, that you remove the first line of the original Section cell, so that only your



Now, you do equivalent steps to copy the CellFrame definition from the Programm style and replace the one in your new style with it.

That's it:

enter image description here

  • $\begingroup$ I didn't read his question that way. BTW you can just do Cell[StyleData["MySec",StyleDefinitions->StyleData["Section"]], ...] to inherit from section style. $\endgroup$ Feb 1 '13 at 6:40
  • $\begingroup$ Now that you say it, I don't read the question that way either. I have read fontstyle instead of fontsize.. :-( $\endgroup$
    – halirutan
    Feb 1 '13 at 6:49
  • $\begingroup$ @halirutan Thanks for your answer. I already knew about copying and pasting, that's why I asked this question: I was hoping for something like FontSize -> Inherit["Section"] $\endgroup$
    – M.R.
    Feb 1 '13 at 7:00

Something like

   FontColor -> CurrentValue[{StyleDefinitions, "Section", "FontColor"}], 
   FontFamily -> CurrentValue[{StyleDefinitions, "Section", "FontFamily"}],
   FontSize -> CurrentValue[{StyleDefinitions, "Section", "FontSize"}] ,
   CellFrame ->CurrentValue[{StyleDefinitions, "Program", "CellFrame"}], 
   Background -> CurrentValue[{StyleDefinitions, "PrintUsage", "Background"}]]]


enter image description here

  • 1
    $\begingroup$ That's pretty slick. Be aware that these styles are not dynamic; if you change the style sheet the style of the generated cell does not change with it. $\endgroup$
    – Mr.Wizard
    Apr 3 '13 at 5:40

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.