fix(pdf): place bottom caption in longtable foot for computational tables#14637
Merged
Conversation
…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.
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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.
When
tbl-cap-location: bottomis 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
longtableand go through "surgery" insrc/resources/filters/customnodes/floatreftarget.luato attach the caption and label. Computational output arrives wrapped in a.cell-output-displayDiv, so the float content is aDivrather than a nativeTable, 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{...}\tabularnewlineimmediately 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: bottomwith a knitrkable()cross-referenced table places the caption below the table.cell-output-displaybehave the sametbl-capfloats (no cell wrapper) are unchangedFixes #14575