Function Repository Resource:

SetDockedCells

Source Notebook

Specify cells to be docked at the top of a notebook window

Contributed by: Lou D’Andria

ResourceFunction["SetDockedCells"][expr]

displays expr in a docked cell in the current notebook.

ResourceFunction["SetDockedCells"][nbobj, expr]

displays a docked cell in the given notebook object.

ResourceFunction["SetDockedCells"][nbobj, {expr1, expr2, }]

displays a sequence of docked cells.

Details and Options

Docked cells are always displayed at the top of the notebook, even when scrolling.
Supported values for expr and expri include:
"text"plain text
TextCell[contents,options]text cell is formatted like text, with appropriate spacing and line breaking
ExpressionCell[contents,options]expression cell can contain any Wolfram Language expressions
Cell[contents,options]arbitrary Cell expression
CellObject[]existing cell to be read from an open notebook
contentsarbitrary Wolfram Language expression to display in an ExpressionCell
Use Cell, TextCell, or ExpressionCell to specify a custom Background, TextAlignment, or any Cell option.
If expr is Inherited the notebook will revert to its default docked cells.
If expr is an empty list any removeable docked cells will be removed.
Docked cells are treated as deployed, so they cannot be edited or selected, but controls in them can be used.
Docked cells can contain Dynamic and DynamicModule objects, but changes to local DynamicModule variables are not stored as they are when they appear in regular notebook content.

Examples

Basic Examples (4) 

Create a new notebook window, and set its docked cell to contain a string:

In[1]:=
ResourceFunction["SetDockedCells"][NotebookCreate[], "docked content"]
Out[1]=

Put a button in the docked cell to save the notebook:

In[2]:=
ResourceFunction["SetDockedCells"][NotebookCreate[], Button["Save", NotebookSave[EvaluationNotebook[]], Method -> "Queued"]]
Out[2]=

Use TextCell to control the styling of docked text:

In[3]:=
ResourceFunction["SetDockedCells"][NotebookCreate[], TextCell["docked content", FontFamily -> "Helvetica", FontSize -> 36, TextAlignment -> Center, Background -> LightBlue]]
Out[3]=

Add multiple docked cells to a notebook:

In[4]:=
ResourceFunction["SetDockedCells"][
 NotebookCreate[], {TextCell["docked content", FontFamily -> "Helvetica", FontSize -> 36, TextAlignment -> Center, Background -> LightBlue], Button["Save", NotebookSave[EvaluationNotebook[]], Method -> "Queued"]}]
Out[4]=

Scope (2) 

Use EvaluationNotebook to refer to the notebook which contains the docked cell:

In[5]:=
ResourceFunction["SetDockedCells"][NotebookCreate[], Row[{ColorSlider[
    Dynamic[CurrentValue[EvaluationNotebook[], Background]]], Button["reset", CurrentValue[EvaluationNotebook[], Background] = Inherited]}]]
Out[5]=

Use Grid to position content in a docked cell:

In[6]:=
nbobj = NotebookCreate[];
ResourceFunction["SetDockedCells"][nbobj, Grid[{{Item["left", Alignment -> "Left"], Item["center", Alignment -> "Center"], Item["right", Alignment -> Right]}}, ItemSize -> Scaled[0.33]]]
Out[6]=

Applications (2) 

Navigate a notebook with controls in its docked cell:

In[7]:=
ResourceFunction["SetDockedCells"][NotebookCreate[], DynamicModule[{cells}, Row[{Dynamic[
     ActionMenu[
      "Select a cell", (Replace[
           CurrentValue[#, CellStyle], {a_} :> a] :> SelectionMove[#, All, Cell]) & /@ cells, Enabled -> (cells =!= {})]], Button["refresh", cells = Cells[EvaluationNotebook[]]]}], Initialization :> (cells = Cells[EvaluationNotebook[]])]]
Out[7]=

Store docked cell state in notebook-level tagging rules:

In[8]:=
ResourceFunction["SetDockedCells"][NotebookCreate[], ExpressionCell[
  ColorSlider[
   Dynamic[CurrentValue[
     EvaluationNotebook[], {TaggingRules, "DockColor"}, LightGray]]], TextAlignment -> Center, Background -> Dynamic[CurrentValue[
     EvaluationNotebook[], {TaggingRules, "DockColor"}]]]]
Out[8]=

Publisher

Lou D'Andria

Version History

  • 1.0.0 – 07 February 2020

Related Resources

License Information