Function Repository Resource:

CaptionCell

Source Notebook

Add a formatted caption to a notebook cell

Contributed by: Michael Sollami

ResourceFunction["CaptionCell"][caption,cell]

adds a caption to the given cell object.

Details and Options

The caption argument may be a styled expression such as a String or Text object.
The cell argument must be a CellObject reference to an existing cell in a notebook.
ResourceFunction["CaptionCell"] creates captions in the form of a CellFrameLabels value that may contain Graphics and Dynamic expressions.
ResourceFunction["CaptionCell"] accepts the following option:
AlignmentLefthorizontally align the caption to the Left,Right,Center or Scaled[s] where s[-1,1]

Examples

Basic Examples (2) 

Create a cell, then add a caption to it:

In[1]:=
1 + 1
Out[1]=
In[2]:=
ResourceFunction["CaptionCell"]["your caption string here...", PreviousCell[]]

Add a styled caption to a cell:

In[3]:=
Button["Add Caption", ResourceFunction["CaptionCell"][
  Style["Caption's text", Purple, 14, Italic, FontFamily -> "Times"], EvaluationCell[]]]
Out[3]=

Scope (2) 

Create a cell caption with formatted Text:

In[4]:=
Plot[Sin[x^2], {x, 0, Pi}]
Out[4]=
In[5]:=
ResourceFunction["CaptionCell"][
  Text[Sin[x^2], BaseStyle -> {14, FontFamily -> "Verdana"}, FormatType -> TraditionalForm], PreviousCell[]];

Caption a cell with framed text:

In[6]:=
ResourceFunction["BirdSay"]["Chirp Chirp"]
Out[6]=
In[7]:=
ResourceFunction["CaptionCell"][
 TextCell["fine art", "Program", CellFrame -> {{2, 2}, {2, 8}}], PreviousCell[]]

Caption a cell with a Row of rainbow text using a ResourceFunction:

In[8]:=
Button["Add rainbow caption", ResourceFunction["CaptionCell"][
  ResourceFunction["RainbowText"]["annotation"], EvaluationCell[]]]
Out[8]=

Options (2) 

Set the horizontal Alignment of the caption to Center:

In[9]:=
sz = {200, 40};
Rasterize[Style["Left", Bold], ColorSpace -> "RGB", RasterSize -> sz] + RandomImage[1, sz, ColorSpace -> "RGB"]
Out[9]=
In[10]:=
ResourceFunction["CaptionCell"][
 Rasterize[Style["Center", Bold], ColorSpace -> "RGB", RasterSize -> sz] + RandomImage[1, sz, ColorSpace -> "RGB"], PreviousCell[], Alignment -> Center]

Set the Alignment of the caption as a Scaled value controlled by a slider:

In[11]:=
a = 1;
Slider[Dynamic[a], {-1, 1, 0.01}]
Out[11]=
In[12]:=
ResourceFunction["CaptionCell"][
 Dynamic@Framed[
   "CaptionCell[..., Alignment \[Rule] Scale[" <> ToString[a] <> "]"],
  PreviousCell[], Alignment -> Dynamic@a]

Publisher

Michael Sollami

Version History

  • 1.0.0 – 30 January 2020

License Information