Skip to content

feat: add chunk option fig.note for figure notes (#2022) - #2453

Merged
yihui merged 5 commits into
masterfrom
feature/fig-note-2022
Aug 26, 2026
Merged

feat: add chunk option fig.note for figure notes (#2022)#2453
yihui merged 5 commits into
masterfrom
feature/fig-note-2022

Conversation

@yihui

@yihui yihui commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Closes #2022.

Adds a new chunk option fig.note to place a note (e.g., a source or explanatory note) below a figure, separate from its caption. Long-requested feature (10+ comments on the issue).

Behavior by output format

  • LaTeX/PDF: emits \figurenote{...} inside the figure environment, after \caption. A default \providecommand{\figurenote} (footnotesize italic) is shipped, so it works out of the box on both the .Rnw and .Rmd→pandoc paths. Users can override it in the preamble, e.g. with the floatrow package:
    \newcommand{\figurenote}[1]{\floatfoot{#1}}
  • HTML: places the note in <p class="figure-note"> inside the figure <div>. A note with no caption still gets a figure <div> (and no empty caption paragraph). A default .figure-note style is added to inst/misc/vignette.css.
  • Typst: emits an emphasized small block after #figure.
  • Office formats (docx/pptx/…) have no semantic equivalent and drop the note silently, consistent with fig.alt.

Plumbing

  • fig.note added to eval.after (inline R in the note evaluated after the chunk), to .recyle.opts (recycled across multiple plots per chunk), and to need_special_plot_hook() so .Rmd→LaTeX routes through hook_plot_tex().

Example

```{r, fig.cap="Monthly sales", fig.note="Source: internal data."}
plot(1:10)
```

Tests

Added cases to tests/testit/test-hooks-latex.R (note placement + empty/NA note) and tests/testit/test-hooks-md.R (HTML figure-note paragraph, with and without a caption). Existing plot/hook tests pass.

🤖 Generated with Claude Code

yihui and others added 3 commits August 26, 2026 12:06
Add a new chunk option `fig.note` to place a note (e.g., a source or
explanatory note) below a figure, separate from its caption.

- LaTeX/PDF: emit `\figurenote{...}` inside the figure environment after
  `\caption`. A default `\providecommand{\figurenote}` (footnotesize
  italic) is shipped so it works out of the box on both the Rnw and
  Rmd->pandoc paths; users can override it in the preamble, e.g. with
  `\newcommand{\figurenote}[1]{\floatfoot{#1}}` (floatrow package).
- HTML: place the note in `<p class="figure-note">` inside the figure
  `<div>`; a note with no caption still gets a figure div (no empty
  caption paragraph). A default style is added to inst/misc/vignette.css.
- Typst: emit an emphasized small block after `#figure`.

`fig.note` is added to `eval.after` (so inline R is evaluated after the
chunk), to `.recyle.opts` (multi-plot recycling), and to
`need_special_plot_hook()` so Rmd->LaTeX routes through hook_plot_tex().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Previously every figure with fig.note carried the full
\providecommand{\figurenote}{...} definition, which was verbose. Since
LaTeX is processed sequentially, define it once (on the first figure note
in a document) via a per-document flag; later notes only call
\figurenote{}. \providecommand remains a no-op when the user has defined
\figurenote in the preamble, so the default and customization both work.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread tests/testit/test-hooks-latex.R Outdated
Comment thread R/plot.R Outdated
yihui and others added 2 commits August 26, 2026 14:56
- keep fig.note near fig.subcap in .recyle.opts to minimize the diff
- use .knitEnv directly in tests (internal objects are visible to testit)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
yihui added a commit to yihui/knitr-examples that referenced this pull request Aug 26, 2026
fig.note is now listed among the options vectorized for multiple plots
per chunk.
@yihui
yihui merged commit 485c14e into master Aug 26, 2026
1 check passed
@yihui
yihui deleted the feature/fig-note-2022 branch August 26, 2026 19:11
@yihui yihui mentioned this pull request Aug 26, 2026
3 tasks
yihui added a commit to yihui/yihui.org that referenced this pull request Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add figure notes option

1 participant