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

[Bug] tabularx and xltabular tables do not work without a caption #2188

Closed
3 tasks done
amarakon opened this issue Oct 21, 2022 · 3 comments · Fixed by #2192
Closed
3 tasks done

[Bug] tabularx and xltabular tables do not work without a caption #2188

amarakon opened this issue Oct 21, 2022 · 3 comments · Fixed by #2192

Comments

@amarakon
Copy link
Contributor

amarakon commented Oct 21, 2022

A few months ago I submitted a pull request that was merged which adds support for tabularx and xltabular tables for LaTeX in kable. If you use one of these and try to make a table without a caption, you will get an error.

---
output:
  pdf_document:
    extra_dependencies: xltabular
---

```{r, echo = FALSE}
library(knitr)

col1 = c("Lorem", "Ipsum")
col2 = c("Dolor", "Sit")

df = data.frame(col1, col2)

# These two will NOT work
kable(df, "latex", tabular = "tabularx")
kable(df, "latex", tabular = "xltabular")
# These two WILL work
kable(df, "latex", tabular = "tabularx", caption = "")
kable(df, "latex", tabular = "xltabular", caption = "")
```

Here is the error I got:

! Missing number, treated as zero.
<to be read again>
                   l
l.70 \begin{tabularx}{l|l}

Error: LaTeX failed to compile file.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See file.log for more info.
Execution halted

shell returned 1

I understand what the problem is, it is using \begin{tabularx}{l|l} instead of \begin{tabularx}{\linewidth}{l|l}. It is strange that not having a caption causes this.


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@amarakon amarakon changed the title [Bug] tabularx and xltabular table do not work without a caption [Bug] tabularx and xltabular tables do not work without a caption Oct 30, 2022
yihui added a commit that referenced this issue Nov 9, 2022
@yihui
Copy link
Owner

yihui commented Nov 9, 2022

It's due to 3ff11db. I don't quite remember the rationale now (perhaps because tabular and longtable work fine without the vertical alignment argument). Anyway, I can definitely fix this problem for tabularx and xltabular.

Or you could use caption = NA. This will avoid generating a caption and will also add {\linewidth}.

@amarakon
Copy link
Contributor Author

Thanks, the issue is fixed now.

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants