Introduction to Toolbars

The Wolfram Language's unique symbolic architecture makes it easy to add toolbars with any possible appearance and action to a Wolfram System notebook.


The ruler is a toolbar used to set the text margins of selected cells and the indentation of cell names and keywords. The notebook ruler can be added to a notebook by selecting Show Ruler in the Window menu or programmatically by using the notebook option WindowToolbars.

WindowToolbars->"RulerBar"notebook option value to show the margin settings ruler
Window Show Rulermenu item toggling the ruler display along the top of a notebook

Show ruler.

For example, the ruler can be shown in the current notebook by evaluating SetOptions[EvaluationNotebook[],WindowToolbars->"RulerBar"].


Docked Cells

Docked cells are cells that are displayed as a toolbar or banner at the top of the notebook and treated as deployed.

DockedCells->cellsnotebook option that gives a list of cells that are displayed as "docked" at the top of the notebook

Docked cells.

While any type of cells can be included in cells, it is recommended that only those with the cell style "DockedCell" be used. The style "DockedCell" ensures that the cell behaves like a toolbar.

One way to implement a docked cell in the current notebook is to use SetOptions[EvaluationNotebook[],DockedCells->cells].

Here is a basic example of a docked cell containing a string.

Click for copyable input


This next example contains the mathematical expression in TraditionalForm.

Click for copyable input


Control objects such as action menus, popup menus, buttons, input fields, etc. can also be used in a docked cell. Create the toolbar contents and then wrap ToBoxes around it to generate the front end box structure automatically. Then place the ToBoxes expression into the BoxData of a Cell. For example, the following input creates an action menu toolbar that places a cell with the chosen style at the insertion point.

Click for copyable input
Click for copyable input


If the spacing between the toolbar elements is static, some elements in a docked cell may become hidden at certain window widths. This can be solved by scaling the item sizes in Grid. The following example includes a label and ButtonBar.

Click for copyable input
Click for copyable input


Multiple docked cells can be included in a notebook.

Click for copyable input


Extended Examples

Word Processing Toolbar

This example includes buttons for setting text alignments and spacings, and opening the font dialog, print dialog, and the Documentation Center. In this example, each of the toolbar elements is generated separately and then converted into boxes using ToBoxes in the CreateWindow statement at the end.

Here is a row of buttons controlling the spacing and alignment of the notebook text:
Click for copyable input
This button opens the Fonts dialog to set formatting options for text selections:
Click for copyable input
This button opens the system print dialog to print the notebook:
Click for copyable input
This button opens the Documentation Center:
Click for copyable input
Here are the labels for the buttons in the toolbar:
Click for copyable input
Here is the completed toolbar in a new notebook:
Click for copyable input


Decorative Toolbar

Images can also be used as docked cells. Below, a 1399×24 pixel image is being used as a decorative docked cell similar to those seen in many stylesheets.

Click for copyable input
Click for copyable input


Defining Toolbars in a Stylesheet

A docked cell can also be defined in a stylesheet instead of in an individual notebook. For example, notebooks with the NaturalColor stylesheet all have the following docked cell at the top of each notebook.


The DockedCells option value for stylesheets is stored in the notebook style definitions cell within a stylesheet notebook. To add a docked cell, start by opening a stylesheet notebook. If the cell does not already exist in the stylesheet, create a new cell with an expression of the form Cell[StyleData["Notebook"]] and place it near the top of the notebook.


Add the docked cell(s) cells to the stylesheet by updating the notebook style definitions cell expression to resemble the following form: Cell[StyleData["Notebook"],DockedCells->{cells}]. For example, print the cell from the previous example.

Click for copyable input

Unformat the printed cell and copy the cell expression into the notebook style definitions cell as the DockedCells option value.


Finally, choose Cell Show Expression to reformat the notebook style definition cell.


Any new notebook with this stylesheet will contain the docked cell.