22
$\begingroup$

I would like to create Mathematica slide shows that contain several tailored, fixed banners as headers and footers, much as MS Powerpoint, MS Word, Apple Pages, and LaTeX documents allow one to specify headers and footers. I would like a more powerful form of Slide Show template in which I design Header1, Footer1, Header2, Footer2, etc., which might contain a corporate logo, colored background, navigation buttons (prior page, next page, etc.), section titles such as Introduction, Approach, Results, Conclusion (for an academic presentation, for instance). During composition, Header1 and Footer1 stay in effect until I deliberately select Header2 and Footer2.

I've searched through Mma SE without full success (How to make the docked cell and the navigation toolbar in the Slide Show?), and the Slide Show palette enables page numbering, dates, and such, but not (as far as I can tell) several header designs containing special figures, text, and so on that can be selected as needed, and re-used within different shows.

$\endgroup$
4
  • 1
    $\begingroup$ Probably you could use FrontEnd`AttachCell for creating the footer. $\endgroup$ Aug 12 at 16:51
  • $\begingroup$ You're far more expert in this realm than I am, so a simple demo code would be much appreciated. (Nevertheless I'll try this when I get a chance.) Thanks! $\endgroup$ Aug 12 at 16:58
  • $\begingroup$ @AlexeyPopkov: I'm happy to post a bounty of +100 on this problem if it would inspire you to solve it. Given the long time in which nobody has solved it, though, I'm worried that I'd simply waste my reputation points. If you leave a comment to the effect that you think you can (truly) solve it, I'll post the bounty to motivate you. (Incidentally, years ago I asked my friend Stephen Wolfram to suggest his team solve it... with no conclusion. This makes me worry that this valuable functionality is simply too difficult in the current versions of Mathematica.) $\endgroup$ Aug 12 at 17:52
  • $\begingroup$ I've added a solution. $\endgroup$ Aug 13 at 8:39

3 Answers 3

4
$\begingroup$

If you start with a simple CreateNotebook["SlideShow"], click Blank Slide from the Classic Slide Show palette and add some text, you get something like that:

enter image description here

Now you create a palette with buttons with code for your different header cells. Here we have two buttons.

CreatePalette[{Button[
   "First banner", 
   NotebookWrite[InputNotebook[], 
    Cell[
     BoxData[
      RowBox[{ToBoxes[
         Text[
          Style["My first banner", 24, Italic, FontFamily -> "Times", 
           Background -> Yellow]]]}]], "DockedCell"]]
   ],
  Button[
   "Second banner", 
   NotebookWrite[InputNotebook[], 
    Cell[
     BoxData[
      RowBox[{ToBoxes[
         Text[
          Style["My second banner", 24, Italic, FontFamily -> "Times",
            Background -> Yellow]]]}]], "DockedCell"]]
   ]
  }]

If you position your cursor just below Slide 1 of 1 and click a button on your palette, it will produce the header cell docked on slide 1. You can then repeat for each slide.

enter image description here

============ ANOTHER APPROACH ============

If you wish to experiment, here is a short Palette with one button. Selecting a presentation and clicking the button will create a docked cell that changes depending on the slide displayed. The presentation is one provided with Mathematica.

CreatePalette[
 Button[
  "Header Cells",
  currentDock = AbsoluteCurrentValue [InputNotebook[], DockedCells];
  SetOptions[InputNotebook[], DockedCells -> AppendTo[currentDock,
     Cell[BoxData[RowBox[{ToBoxes[Text[Style[
            Dynamic[
             contents = Switch[
               
               val = 
                Refresh[
                 CurrentValue[{"CounterValue", 
                   "SlideShowNavigationBar"}], UpdateInterval -> 1],
               1, Text[" Slide 1"],
               2, Text[" Slide 2"],
               3, 
               Row[{Import["ExampleData/spikey.tiff", 
                  ImageSize -> Small], Text[" Slide 3"]}],
               4, Text[" Slide 4"],
               5, Text[" Slide 5"],
               6, Text[" Slide 6"],
               _, Text[""]
               ]],
            24, Italic, FontFamily -> "Times", 
            Background -> Yellow]]]}]], "DockedCell", 
      Background -> LightBlue
      ]
     ]
   ]
  ]
 ]

enter image description here

$\endgroup$
6
  • $\begingroup$ Thanks so much... I'm working on this and struggling just a bit. Give me time and I'll make sure I know how to do this. Then I will most heartily and graciously accept! $\endgroup$ Aug 14 at 2:34
  • $\begingroup$ This is great! ($\checkmark$). The only way it could be improved is if each banner got inherited. As it stands I must add a new banner to each slide. I'm willing to do this, but some form of inheritance would be a bit better. $\endgroup$ Aug 14 at 2:41
  • $\begingroup$ Unfortunately, this method doesn't create true docked cells, and when you scroll down the slide your header cell will become invisible. You simply create usual cells with style "DockedCell", not DockedCells. $\endgroup$ Aug 14 at 5:06
  • 1
    $\begingroup$ I added a possible approach with a real docked cell. $\endgroup$ Aug 16 at 10:21
  • $\begingroup$ Interesting. I didn't know that the whole Cell expression for DockedCells can be wrapped with Dynamic. But while this approach works, I do experience noticeable UI lags as I scroll through the presentation. So it's probably not the best idea though. $\endgroup$ Aug 16 at 12:49
4
$\begingroup$

A partial answer is the following:

With[{myCell = 
   Cell[BoxData[
     RowBox[{ToBoxes[
        Text[Style["My banner", 24, Italic, FontFamily -> "Times", 
          Background -> Yellow]]]}]], "DockedCell"]},
 nb = NotebookCreate[
   ScreenStyleEnvironment -> "SlideShow",
   DockedCells -> 
    Dynamic[If[
      CurrentValue[EvaluationNotebook[], ScreenStyleEnvironment] === 
       "SlideShow",
      {Inherited, myCell}, myCell]]]]

This then creates a SlideShow notebook that has my fixed banner at the top. I don't know how to create a "footer" banner, nor change one within the SlideShow notebook.

enter image description here

I wouldn't mind (too much) if I had to make several separate SlideShows with different headers and then concatenate them into a single SlideShow retaining the separate headers, but apparently this is not possible.

$\endgroup$
4
$\begingroup$

You can create a footer using AttachCell (new in Mathematica 12.2):

footerObj = 
 AttachCell[EvaluationNotebook[], 
  Panel[Style["Footer", 30], ImageSize -> {Full, All}, Background -> LightBlue, 
   Alignment -> Center], "Inline", 2, Bottom]

Here is how it is displayed in the "SlideShow" environment:

screenshot

If you use Mathematica version lower than 12.2, try FrontEnd`AttachCell instead.

Since attached cells (as well as docked cells) support Dynamic, you can make them dependent on the slide number using CurrentValue[{"CounterValue", "SlideShowNavigationBar"}]:

footerObj = 
 AttachCell[nb, 
  Panel[Style[
    Row[{"Footer of Slide ", 
      Dynamic@CurrentValue[{"CounterValue", "SlideShowNavigationBar"}]}], 30], 
   ImageSize -> {Full, All}, Background -> LightBlue, Alignment -> Center], "Inline", 2, 
  Bottom]

screenshot

Of course, you can write a function which will display a predefined expression on the current footer depending on the slide number.

You can even automatically extract and display the heading of the selected section on the slide using an approach similar to this one.


Since the attached cells exist only diring current session and will be lost upon saving and reopening the Notebook, it is reasonable to put the code for them into NotebookDynamicExpression.

$\endgroup$
2
  • $\begingroup$ AlexeyPopkov: Thanks so much ($+1$). But I knew how to put on a footer. The core problem, as explained, is that you must be able to CHANGE headers (and footers) within a single slide show. Use Header1, then Header2, then Header3, e.g., Introduction, then later Method, then Results, then Conclusions. Each with a variable number of pages as I add or subtract slides in different sections. If you're familiar with MS Powerpoint, or Apple Keynote, and such... that is what I seek. Can you solve THAT? Definitely worth 100 reputation points to me! $\endgroup$ Aug 13 at 15:53
  • 1
    $\begingroup$ @DavidG.Stork I've updated the answer to include a method to achieve what you want. $\endgroup$ Aug 14 at 5:22

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.