Let table captions use the full column width

An HTML <caption> box is constrained to its table's width, so long
captions above narrow tables wrapped into many short lines. Move each
caption out of its table into a <p class="caption table-caption"> right
above it (keeping the bookdown numbering span and its #tab:... anchor),
so captions can span the full column width instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Change-Id: I3fdb38298c672de2aaa2d1cb66f61a2793f98adb
diff --git a/inst/rmarkdown/templates/posterdown_ids/resources/template.html b/inst/rmarkdown/templates/posterdown_ids/resources/template.html
index 255d382..967ee77 100644
--- a/inst/rmarkdown/templates/posterdown_ids/resources/template.html
+++ b/inst/rmarkdown/templates/posterdown_ids/resources/template.html
@@ -392,6 +392,13 @@
 padding-bottom: 3mm;
 
 }
+p.caption.table-caption {
+text-align: center;
+margin-bottom: 0;
+}
+p.caption.table-caption + table {
+margin-top: 2mm;
+}
 code {
 font-size: 1em;
 font-family: monospace;
@@ -1314,8 +1321,19 @@
 // kableExtra::kable_styling(font_size = ...) adds an inline
 // "font-size: initial !important;" to table captions, which no stylesheet
 // rule can override. Strip it so the template's caption styling applies.
+// Also move each caption out of its table into a <p class="caption"> above
+// it: an HTML <caption> box is constrained to the table's width, so long
+// captions above narrow tables wrap into many short lines. As a block-level
+// paragraph the caption can use the full column width instead. The
+// bookdown numbering span (with its #tab:... anchor) is moved along.
 document.querySelectorAll("table caption").forEach(function (el) {
   el.style.removeProperty("font-size");
+  var table = el.closest("table");
+  var p = document.createElement("p");
+  p.className = "caption table-caption";
+  while (el.firstChild) p.appendChild(el.firstChild);
+  table.parentNode.insertBefore(p, table);
+  el.remove();
 });
 </script>