feat: add chunk option fig.note for figure notes (#2022) - #2453
Merged
Conversation
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>
yihui
commented
Aug 26, 2026
- 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
added a commit
to yihui/yihui.org
that referenced
this pull request
Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2022.
Adds a new chunk option
fig.noteto 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
\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.Rnwand.Rmd→pandoc paths. Users can override it in the preamble, e.g. with the floatrow package:<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-notestyle is added toinst/misc/vignette.css.#figure.fig.alt.Plumbing
fig.noteadded toeval.after(inline R in the note evaluated after the chunk), to.recyle.opts(recycled across multiple plots per chunk), and toneed_special_plot_hook()so.Rmd→LaTeX routes throughhook_plot_tex().Example
Tests
Added cases to
tests/testit/test-hooks-latex.R(note placement + empty/NA note) andtests/testit/test-hooks-md.R(HTML figure-note paragraph, with and without a caption). Existing plot/hook tests pass.🤖 Generated with Claude Code