Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

Update

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

Cell[StyleData["MySec"],

stays.

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

share|improve this answer
    
I didn't read his question that way. BTW you can just do Cell[StyleData["MySec",StyleDefinitions->StyleData["Section"]], ...] to inherit from section style. –  Mike Honeychurch Feb 1 '13 at 6:40
    
Now that you say it, I don't read the question that way either. I have read fontstyle instead of fontsize.. :-( –  halirutan Feb 1 '13 at 6:49
    
@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"] –  M.R. Feb 1 '13 at 7:00
add comment

Something like

  CellPrint[Cell["text", 
   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

share|improve this answer
    
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. –  Mr.Wizard Apr 3 '13 at 5:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.