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.

For custom stylesheets, it's nice to have a graphic banner in the Docked Cell. According to the doc page tutorial/IntroductionToToolbars, this is how you do it, but it seem a bit overkill:

img = Rasterize[
   Framed["\tMy Header", Background -> LightBlue, FrameStyle -> White,
     ImageSize -> {2000, 30}]];
image = Cell[
   BoxData[ToBoxes[
      img] /. {(ImageSize -> {___, ___}) -> (ImageSize -> 
         ImageDimensions[img])}], "DockedCell", CellMargins -> -2, 
   CellFrameMargins -> {{0, 0}, {0, 0}}];
SetOptions[InputNotebook[], DockedCells -> {image}]
share|improve this question
    
Thanks for the Accept! –  Mr.Wizard Jun 15 '12 at 1:51

2 Answers 2

up vote 7 down vote accepted

I'm not sure from your question if you need the docked cell to be an image. I cannot see why you would unless you already have a rendered image, and that is not what you show. Here is what I use:

myCell = Cell[
   "Title Goes Here", "DockedCell",
   CellFrameColor -> RGBColor[0.996109, 0.500008, 0],
   Background -> GrayLevel[0.750011],
   CellFrame -> {{0, 0}, {3, 0}},
   CellMargins -> {{0, 0}, {10, 0}},
   TextAlignment -> -0.5,
   FontFamily -> "Helvetica",
   FontSize -> 30
 ];

SetOptions[InputNotebook[], DockedCells -> myCell]

enter image description here


If you do in fact need to set an image as the docked cell the method you have looks reasonable, but I believe it can be simplified by using Magnification -> 1 and a simpler form for CellFrameMargins.

Using this image: (drag into a Notebook and set img =)

enter image description here

SetOptions[InputNotebook[],
  DockedCells -> 
    Cell[BoxData@ToBoxes@Image[img, Magnification -> 1],
     "DockedCell",
     CellFrame -> 0,
     CellFrameMargins -> 0
    ]
]

enter image description here

share|improve this answer
    
How would you do it simpler for a rendered image? I guess that's what he was getting at... –  rm -rf Jun 1 '12 at 20:59
    
@R.M okay I tried to address that too. –  Mr.Wizard Jun 1 '12 at 21:25
    
I wasn't quite clear — what you have here is fine and the BoxData@ToBoxes approach is what the OP had in the question. But they were talking about a custom stylesheet, and I haven't found a way to get any evaluatable content (which img here is) into a stylesheet. It is essentially inert and the way that images are inserted in to stylesheets is by exporting the image as an encoded string and wrapping it in GraphicsData... something along the lines of Cell[GraphicsData["Bitmap","thousandsOfCharactersOfEncodedJibberish"],...]. –  rm -rf Jun 1 '12 at 21:35
    
@R.M ah, I think I understand now finally. I think what you propose is standard. –  Mr.Wizard Jun 1 '12 at 21:45
    
Do you know what that encoding is? I haven't been able to export an image into any reasonable string that GraphicsData can understand... All I can see from poking around are pre-encoded stuff in existing stylesheets, but no info on how to convert one of my own –  rm -rf Jun 1 '12 at 21:45

Nothwithstanding the answer from Mr.Wizard and discussion with @R.M it seems like you want to make a stylesheet with a docked cell ...right?

img = Plot[Sin[x^2], {x, -3, 3},
  Axes -> False,
  AspectRatio -> 0.25,
  BaseStyle -> Directive[FontFamily -> "Helvetica", 9],
  Frame -> True,
  FrameLabel -> {{"x axis", None}, {"y axis", None}},
  ImageSize -> 200,
  ImagePadding -> {{40, 1}, {30, 1}}]

Note that I have made this image just for testing purposes. If you have a JPEG or similar then just past it directly where you see img below. Once you have your image:

CellPrint[
 Cell[StyleData[All, "Working"],
  DockedCells -> {First[ToBoxes[
      TextCell[Row[{img, Spacer[20], Style["My Docked Cell", 24]}], 
       Background -> GrayLevel[0.8], CellMargins -> 0]
      ]]}]
 ] 

enter image description here

This generated cell can be added to your stylesheet. Before cutting and pasting this cell into the stylesheet make sure to click on the cell bracket and go to the options inspector and set GeneratedCells->False and CellAutoOverwrite->False.

enter image description here

You need to do this because having these set to True in the stylesheet with lead to some screwy behaviour.

Alternatively to make it entirely programmatic you can do this:

CreateDocument@Notebook[{
   Cell[StyleData[StyleDefinitions -> "Default.nb"]],
   Cell[StyleData[All, "Working"],
    DockedCells -> {First[ToBoxes[
        TextCell[Row[{img, Spacer[20], Style["My Docked Cell", 24]}], 
         Background -> GrayLevel[0.8], CellMargins -> 0]
        ]]}]},
  StyleDefinitions -> "PrivateStylesheetFormatting.nb"]

enter image description here

and save the resulting notebook as a stylesheet.

As far as creating cells like Cell[GraphicsData["Bitmap","thousandsOfCharactersOfEncodedJibberish"],...] goes I do not know how to make the resulting cell have the graphics information in this format. For my purposes this has never been a problem but I guess for large graphics there could be some advantages w.r.t to overall size.

share|improve this answer

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.