Code Cells: Jupyter

Jupyter is an open document format that supports computations in many languages including Python, R, and Julia. Learn more about using Jupyter with Quarto in the article on Running Code.

Overview

Cell options affect the execution and output of executable code blocks. They are specified within comments at the top of a block. For example:

```{python}
#| label: fig-polar
#| echo: false
#| fig-cap: "A line plot on a polar axis"
```

Attributes

label

Unique label for code cell. Used when other code needs to refer to the cell (e.g. for cross references fig-samples or tbl-summary)

classes

Classes to apply to cell container

tags

Array of tags for notebook cell

id

Notebook cell identifier. Note that if there is no cell id then label will be used as the cell id if it is present. See https://jupyter.org/enhancement-proposals/62-cell-id/cell-id.html for additionanl details on cell ids.

Code Output

eval

Evaluate code cells (if false just echos the code into output).

echo

Include cell source code in rendered output. Specify fenced to include the cell delimiter as part of the output.

code-fold

Collapse code into an HTML <details> tag so the user can display it on-demand. Specify show to have the code initiallly visible.

code-summary

Summary text to use for code blocks collapsed using code-fold

code-overflow

Choose whether to scroll or wrap when code lines are too wide for their container.

code-line-numbers

Include line numbers in code block output.

lst-label

Unique label for code listing (used in cross references)

lst-cap

Caption for code listing

Cell Output

output

Include the results of executing the code in the output (specify asis to treat output as raw markdown with no enclosing containers).

warning

Including warnings in rendered output.

error

Include errors in the output (note that this implies that errors executing code will not halt processing of the document).

include

Catch all for preventing any output (code or results) from being included in output.

panel

Panel type for cell output (tabset, input, sidebar, fill, center)

Figures

fig-cap

Figure caption

fig-subcap

Figure subcaptions

fig-link

Hyperlink target for the figure

fig-align

Horizontal alignment for the figure (default, left, right, or center)

fig-alt

Alternative text to be used in the alt attribute of HTML images.

fig-env

LaTeX environment for figure output

fig-pos

LaTeX figure position arrangement to be used in \begin{figure}[].

fig-scap

A short caption (only used in LaTeX output). A short caption is inserted in \caption[], and usually displayed in the “List of Figures” of a PDF document.

Tables

tbl-cap

Table caption

tbl-subcap

Table subcaptions

tbl-colwidths

Apply explicit table column widths for markdown grid tables and pipe tables that are more than columns characters wide (72 by default).

Some formats (e.g. HTML) do an excellent job automatically sizing table columns and so don’t benefit much from column width specifications. Other formats (e.g. LaTeX) require table column sizes in order to correctly flow longer cell content (this is a major reason why tables > 72 columns wide are assigned explicit widths by Pandoc).

This can be specified as:

  • auto: Apply markdown table column widths except when there is a hyperlink in the table (which tends to throw off automatic calculation of column widths based on the markdown text width of cells). (auto is the default for HTML output formats)

  • true: Always apply markdown table widths (true is the default for all non-HTML formats)

  • false: Never apply markdown table widths.

  • [40,30,30]: Array of explicit width percentages.

Panel Layout

layout

2d-array of widths where the first dimension specifies columns and the second rows.

For example, to layout the first two output blocks side-by-side on the top with the third block spanning the full width below, use [[3,3], [1]].

Use negative values to create margin. For example, to create space between the output blocks in the top row of the previous example, use [[3,-1, 3], [1]].

layout-ncol

Layout output blocks into columns

layout-nrow

Layout output blocks into rows

layout-align

Horizontal alignment for layout content (default, left, right, or center)

layout-valign

Vertical alignment for layout content (default, top, center, or bottom)

Page Columns

column

Page column for output

fig-column

Page column for figure output

tbl-column

Page column for table output

cap-location

Where to place figure and table captions (top, bottom, or margin)

fig-cap-location

Where to place figure captions (top, bottom, or margin)

tbl-cap-location

Where to place table captions (top, bottom, or margin)