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

Multi-column table output prioritizes center of new page or top of new page in PDF #11684

Closed
pentagramswheel opened this issue Dec 14, 2024 · 8 comments
Labels
support a request for support

Comments

@pentagramswheel
Copy link

pentagramswheel commented Dec 14, 2024

Bug description

I am trying to use the YAML chunk options mentioned in Table Computations to create a two-column output with separate tables. I am observing one of the following two cases:

  1. If I have a Markdown chunk leading up to a multi-column kable print, where a PDF page break occurs in the middle of the Markdown chunk, then the kable print interrupts the chunk at the top of the following page before continuing the Markdown preceding it sequentially.
  2. If I have the same lead-up at the end of a document, but no page break needs to occur, the kable print is "skipped" sequentially so that it can be printed at the center of the following page.

Steps to reproduce

Case 1:

---
title: "Project Title"
author: "Author"
format:
  pdf: default
  gfm: default
date: "2024-12-06"
sansfont: "Times New Roman"
mainfont: "Times New Roman"
---

```{r}
#| label: imports
#| include: false
library(knitr)
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.1

```{r}
#| label: r-chunk1
var <- 4
var2 <- 5
var3 <- 6
var4 <- 7
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.2

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.3

```{r}
#| label: r-chunk2
#| echo: false
tbl1 = data.frame(reason = c("Catgeory 1", "Catgeory 2", "Catgeory 3", "Catgeory 4", "Category 5"),
                  n = c(43, 23, 4, 7, 63))
tbl2 = data.frame(reason = c("Catgeory 1", "Catgeory 2", "Catgeory 3"),
                  n = c(32, 4, 11))
```

```{r}
#| label: tbl-counts
#| echo: false
#| tbl-cap: "Counts"
#| tbl-subcap: 
#|   - "Table 1"
#|   - "Table 2"
#| layout-ncol: 2
knitr::kable(tbl1)
knitr::kable(tbl2)
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.4

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.5

Case 2:

---
title: "Project Title"
author: "Author"
format:
  pdf: default
  gfm: default
date: "2024-12-06"
sansfont: "Times New Roman"
mainfont: "Times New Roman"
---

```{r}
#| label: imports
#| include: false
library(knitr)
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.1

```{r}
#| label: r-chunk1
var <- 4
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.2

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.3

```{r}
#| label: r-chunk2
#| echo: false
tbl1 = data.frame(reason = c("Catgeory 1", "Catgeory 2", "Catgeory 3", "Catgeory 4", "Category 5"),
                  n = c(43, 23, 4, 7, 63))
tbl2 = data.frame(reason = c("Catgeory 1", "Catgeory 2", "Catgeory 3"),
                  n = c(32, 4, 11))
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.4

```{r}
#| label: tbl-counts
#| echo: false
#| tbl-cap: "Counts"
#| tbl-subcap: 
#|   - "Table 1"
#|   - "Table 2"
#| layout-ncol: 2
knitr::kable(tbl1)
knitr::kable(tbl2)
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.5

Expected behavior

PDF Export Case 1:
Table 1 should print after the 3rd "lorem ipsum" paragraph.

PDF Export Case 2:
Table 1 should print after the 4th "lorem ipsum" paragraph.

Actual behavior

PDF Export Case 1:
Table 1 prints at the top of Page 2, in the middle of the 5th "lorem ipsum" paragraph.

PDF Export Case 2:
Table 1 prints after the 5th "lorem ipsum" paragraph and at the center of Page 2.

Your environment

R version 4.4.1 (2024-06-14)
IDE/Platform: Sublime Text 3
OS: MacOS Sequoia 15.1.1

Quarto check output

Quarto 1.6.39
[✓] Checking environment information...
      Quarto cache location: /Users/wilaquino/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.6.39
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: v2024.12
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/wilaquino/Library/TinyTeX/bin/universal-darwin
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.4
      Path: /Library/Frameworks/Python.framework/Versions/3.12/bin/python3
      Jupyter: 5.7.2
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.4.1
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library
      knitr: 1.48
      rmarkdown: 2.28

[✓] Checking Knitr engine render......OK
@pentagramswheel pentagramswheel added the bug Something isn't working label Dec 14, 2024
@mcanouil
Copy link
Collaborator

Could you update your code to be fully reproducible?
We need actual "working" code, not pseudo-code.
Thank you!

@mcanouil mcanouil added the needs-repro Issues that are blocked until reporter provides an adequate reproduction label Dec 14, 2024
@pentagramswheel
Copy link
Author

pentagramswheel commented Dec 16, 2024

It turns out this was not a Quarto problem but a potential problem with the knitr package working with LaTeX and figures/tables/etc. I wanted to research more about the problem first before adding an edit here. I found the following threads talking about problems similar to mine, with reproducible examples and solutions:

The conclusion I came to is that knitr::kable is at least partially derived from LaTeX when it comes to printing figures/tables/etc which "floats" said objects according to some formula. Maybe that is not completely true, but since I found a solution, I don't plan to look into it more currently.

The problem described in the above threads occurred when I was using the Quarto documentation syntax for tables. Adding the following header-includes block in the YAML header for my project is what fixed my tables from pushing away/against any other content:

---
title: "Title"
author: "Author"
format:
  pdf: default
  gfm: default
date: "2024-12-16"
sansfont: "Times New Roman"
mainfont: "Times New Roman"

# fix table floats
header-includes:
  - \usepackage{float}
  - \floatplacement{table}{H}
---

```{r}
#| label: imports
#| include: false
library(tidyverse)
library(lubridate)
library(readxl)
library(knitr)
```

<!-- Other R and Markdown chunks -->

```{r}
#| label: tbl-label
#| echo: false
#| tbl-cap: "Caption"
#| tbl-subcap: 
#|   - "Subcaption 1"
#|   - "Subcaption 2"
#| layout-ncol: 2
knitr::kable(tbl1)
knitr::kable(tbl2)
```

Should I still edit my original post @mcanouil ?

@mcanouil
Copy link
Collaborator

mcanouil commented Dec 16, 2024

First header-includes is not a Quarto option, it's a Pandoc option which basically pass through.
Second, I don't believe you need that at all in Quarto, for instance for figure there is fig-pos which allows you to set H as LaTeX positioning, but without a small reproducible example of the issue, it's not possible to investigate.
Even your last example, is not reproducible (nobody can use it) and requires a lot of R packages for no clear reason (i.e., knitr seems to be the only needed and asking to install the whole tidyverse is overkill).

So, yes, please provide a small reproducible example. It would be appreciated.

@pentagramswheel
Copy link
Author

pentagramswheel commented Dec 16, 2024

@mcanouil The tidyverse package and some of the others were needed for my bigger project, but I've now updated the original post with a small but full reproducible example. How does it look? I also see fig-pos for the Figures chunks. Is there a tables equivalent for Quarto?

@mcanouil
Copy link
Collaborator

Here is what I get adding tbl-pos: H in the code cell.

Image
qmd
---
title: "Project Title"
author: "Author"
format: pdf
---

```{r}
#| label: imports
#| include: false
library(knitr)
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.1

```{r}
#| label: r-chunk1
var <- 4
var2 <- 5
var3 <- 6
var4 <- 7
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.2

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.3

```{r}
#| label: r-chunk2
#| echo: false
tbl1 = data.frame(reason = c("Catgeory 1", "Catgeory 2", "Catgeory 3", "Catgeory 4", "Category 5"),
                  n = c(43, 23, 4, 7, 63))
tbl2 = data.frame(reason = c("Catgeory 1", "Catgeory 2", "Catgeory 3"),
                  n = c(32, 4, 11))
```

```{r}
#| label: tbl-counts
#| echo: false
#| tbl-pos: H
#| tbl-cap: "Counts"
#| tbl-subcap: 
#|   - "Table 1"
#|   - "Table 2"
#| layout-ncol: 2
knitr::kable(tbl1)
knitr::kable(tbl2)
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.4

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.5

@mcanouil mcanouil added tables Issues with Tables including the gt integration latex LaTeX engines related libraries and technologies and removed needs-repro Issues that are blocked until reporter provides an adequate reproduction labels Dec 16, 2024
@pentagramswheel
Copy link
Author

That is exactly what I needed. After cross-referencing with other issues and discussions, I see that it's mentioned in the future milestones already as well. Thank you!

@mcanouil
Copy link
Collaborator

mcanouil commented Dec 17, 2024

I am going to reopen because tbl-pos is not documented anywhere inside Quarto and does not seem to work at top level (it works in a code cell and in a fenced div).

The first issue I am aware of using tbl-pos is:

@mcanouil mcanouil reopened this Dec 17, 2024
@mcanouil mcanouil added the triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. label Dec 17, 2024
@mcanouil mcanouil assigned cderv and cscheid and unassigned cderv Dec 17, 2024
@mcanouil
Copy link
Collaborator

Never mind, let's close this one.

@mcanouil mcanouil added support a request for support and removed bug Something isn't working crossref tables Issues with Tables including the gt integration latex LaTeX engines related libraries and technologies triaged-to Issues that were not self-assigned, signals that an issue was assigned to someone. labels Dec 18, 2024
@mcanouil mcanouil closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support a request for support
Projects
None yet
Development

No branches or pull requests

4 participants