Skip to content

fix(pdf): place bottom caption in longtable foot for computational tables#14637

Merged
cderv merged 2 commits into
mainfrom
fix/issue-14575
Jun 30, 2026
Merged

fix(pdf): place bottom caption in longtable foot for computational tables#14637
cderv merged 2 commits into
mainfrom
fix/issue-14575

Conversation

@cderv

@cderv cderv commented Jun 30, 2026

Copy link
Copy Markdown
Member

When tbl-cap-location: bottom is set, a cross-referenceable computational (knitr/Jupyter) table renders its caption inside the table body, above the bottom rule, instead of below the table.

Root Cause

Cross-referenceable tables are emitted as longtable and go through "surgery" in src/resources/filters/customnodes/floatreftarget.lua to attach the caption and label. Computational output arrives wrapped in a .cell-output-display Div, so the float content is a Div rather than a native Table, and the surgery path handled bottom captions by inserting the caption after the data rows but still inside the longtable body. The native-table path was already correct, which is why the bug only showed up for engine output.

Fix

On the surgery path, inject the caption into the longtable foot — \caption{...}\tabularnewline immediately before \endlastfoot — so it renders below the table, matching Pandoc's native longtable output. A longtable with no foot (e.g. kable(longtable = TRUE), whose output has no \endlastfoot) falls through to the previous behavior unchanged; that orphaned-caption shape is a separate issue, out of scope here.

Test Plan

  • tbl-cap-location: bottom with a knitr kable() cross-referenced table places the caption below the table
  • Markdown tables wrapped in .cell-output-display behave the same
  • Plain markdown tables and tbl-cap floats (no cell wrapper) are unchanged
  • Top caption placement is unaffected

Fixes #14575

cderv added 2 commits June 30, 2026 14:00
…bles (#14575)

With tbl-cap-location: bottom, a cross-referenceable table whose content
is wrapped in .cell-output-display (knitr/Jupyter engine output) routes
through floatreftarget.lua's manual longtable surgery instead of Pandoc's
native path. That branch emitted the caption after the data rows but
inside the longtable body, so it rendered inside the table rather than
below it.

Inject the caption (plus \tabularnewline) immediately before \endlastfoot
so it lands in the longtable foot, matching the native path. Top captions
and footless tables (e.g. kable(longtable=TRUE)) fall through to the prior
behavior; the latter is tracked separately as a follow-up.
@posit-snyk-bot

posit-snyk-bot commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@cderv cderv merged commit 14ef83b into main Jun 30, 2026
51 checks passed
@cderv cderv deleted the fix/issue-14575 branch June 30, 2026 13:28
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.

Table title included in table in pdf file if tbl-cap-location:bottom

2 participants