Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wide table runs into caption contingent on label prefix when using tinytable #83

Open
fkohrt opened this issue Aug 22, 2024 · 1 comment

Comments

@fkohrt
Copy link
Contributor

fkohrt commented Aug 22, 2024

If I create a table using tinytable that is very wide, the caption is at risk of being struck through:

---
title: "Test Document"
author:
  - name: Test Author
    affiliations:
      city: Los Angeles
      region: CA
lang: en
format:
  apaquarto-pdf:
    documentmode: man
keep-tex: true
---

```{r}
#| label: "tbl-descriptive-statistics"
#| echo: false
#| tbl-cap: "Summary Statistics"

# Install dev version of `tinytable`
# remotes::install_github("vincentarelbundock/tinytable")

library(tinytable)
tt(head(iris))
```

Screenshot from 2024-08-22 16-09-29

Curiously, removing the tbl- prefix from the label resolves the issue:

Screenshot from 2024-08-22 16-10-24

Initially raised at vincentarelbundock/tinytable#327, where the following was also noted:

And for reference, here's the LaTeX that this produces. Note that the only code that tinytable generates is the \begin{tblr} block, and that the issue stems for a conflict between a vanilla tblr environment and the table and caption commands inserted by Quarto and/or apaquarto.

\begin{table}

{\caption{{Summary Statistics}{\label{tbl-descriptive-statistics}}}
\vspace{-20pt}}

\centering
\begin{tblr}[         %% tabularray outer open
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]Q[]Q[]Q[]},
}                     %% tabularray inner close
\toprule
Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species \\ \midrule %% > TinyTableHeader
5.1 & 3.5 & 1.4 & 0.2 & setosa \\
4.9 & 3.0 & 1.4 & 0.2 & setosa \\
4.7 & 3.2 & 1.3 & 0.2 & setosa \\
4.6 & 3.1 & 1.5 & 0.2 & setosa \\
5.0 & 3.6 & 1.4 & 0.2 & setosa \\
5.4 & 3.9 & 1.7 & 0.4 & setosa \\
\bottomrule
\end{tblr}

\end{table}
fkohrt added a commit to lmu-osc/code-publishing that referenced this issue Aug 23, 2024
@wjschne
Copy link
Owner

wjschne commented Aug 25, 2024

This was caused by a hacky solution of mine to a problem with longtable (the default environment for quarto tables). The longtable environment does not play nicely with the apa7 package that apaquarto depends on to make .pdf via LaTeX. I am not sure what to do about it, but I have inserted a possible fix. By default, apaquarto removes 20pt of extra space (i.e., \vspace{-20pt}) between captions and tables when in manuscript mode. Using tinytable, longtable is not used, and space should not be subtracted. If I can find a way to take care of the problem automatically, I will do it. In the meantime, you can now add after-caption-space: 0pt as a code-chunk option. For example:

---
title: "Test Document"
author:
  - name: Test Author
    affiliations:
      city: Los Angeles
      region: CA
lang: en
format:
  apaquarto-pdf:
    documentmode: man
keep-tex: true
---

```{r}
#| label: "tbl-descriptive-statistics"
#| echo: false
#| tbl-cap: "Summary Statistics"
#| after-caption-space: 0pt

library(tinytable)
tt(head(iris))
```

Screenshot 2024-08-25 121626

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

No branches or pull requests

2 participants