Open rdtmcl opened 7 months ago
Thanks for the report. Could you properly format your message to make the code legible?
You can share a self-contained "working" (reproducible) Quarto document using the following syntax, i.e., using more backticks than you have in your document (usually four ````
).
See https://quarto.org/bug-reports.html#small-is-beautiful-aim-for-a-single-document-with-10-lines.
If you have multiple files (and if it is absolutely required to have multiple files), please share as a Git repository.
````qmd
---
title: "Reproducible Quarto Document"
format: html
engine: knitr
---
This is a reproducible Quarto document using `format: html`.
It is written in Markdown and contains embedded R code.
When you run the code, it will produce a plot.
```{r}
plot(cars)
The end.
Additionally and if not already given, please share the output of quarto check
within a code blocks (i.e., using three backticks ```txt
), see https://quarto.org/bug-reports.html#check.
I can repro this, specifically the combination of column: page
and the layout option.
FYI, the issue is with code cell column: page
while it works properly using fenced divs.
Quarto document | HTML |
---|---|
````qmd --- title: "Reproducible Quarto Document" format: html engine: knitr --- ```{r} #| label: ggplot2 #| include: false #| eval: false library(ggplot2) ggplot(mpg, aes(x = hwy, y = cty, color = cyl)) + geom_point(alpha = 0.5, size = 2) + scale_color_viridis_c() + theme_minimal() ggplot(mpg, aes(x = hwy, y = cty, color = displ)) + geom_point(alpha = 0.5, size = 2) + scale_color_viridis_c(option = "E") + theme_minimal() ``` ## Codel cell option ```{r} #| ref-label: ggplot2 #| label: fig-mpg1 #| fig-cap: "City and highway mileage for 38 popular models of cars." #| fig-subcap: #| - "Color by number of cylinders" #| - "Color by engine displacement, in liters" #| layout-ncol: 2 #| column: page ``` ## Fenced div ::: {.column-page} ```{r} #| ref-label: ggplot2 #| label: fig-mpg2 #| fig-cap: "City and highway mileage for 38 popular models of cars." #| fig-subcap: #| - "Color by number of cylinders" #| - "Color by engine displacement, in liters" #| layout-ncol: 2 ``` ::: ```` |
I was about to post this; for the time being, you can use the ::: column-page
workaround, but we'll fix the bug.
I met this issue today, I found the ::: column-page
solution, but another problem arised: this solution interferes with the pdf render. Here's the example I worked with:
---
title: "test"
format: pdf
---
::: column-page
```{r}
#| label: fig-test
#| fig-cap: LaTeX crash?
#| fig-subcap:
#| - Test A
#| - Test B
#| layout-ncol: 2
library(ggplot2)
iris |>
ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point()
iris |>
ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point()
:::
This renders well with `quarto render --to html`, but produces the following error with `--to pdf`:
Rendering PDF running xelatex - 1 This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex) restricted \write18 enabled. entering extended mode
updating tlmgr
updating existing packages ERROR: compilation failed- error LaTeX Error: Not in outer par mode.
See the LaTeX manual or LaTeX Companion for explanation.
Type H
l.209
I searched the internet a bit about this error, and it appears to stem from the fact that Quarto tries to enclose a float in a box, which LaTeX doesn't like, but my understanding of what's going on stops there. For now I'm going to try conditional content to have one chunk enclosed in the div for HTML, and one without for PDF.
I'll share the (clunky) workaround I found to have both renders working with the same code, if it can help anyone with the same needs:
---
title: "test"
format:
html: default
pdf: default
---
```{r}
#| label: test-plot
#| eval: false
#| include: false
library(ggplot2)
iris |>
ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point()
iris |>
ggplot(aes(x = Sepal.Length, y = Sepal.Width)) +
geom_point()
::: {.content-visible unless-format="pdf"} ::: column-page
#| ref-label: test-plot
#| label: fig-test-html
#| fig-cap: Does it work?
#| fig-subcap:
#| - Test A
#| - Test B
#| layout-ncol: 2
::: :::
::: {.content-visible when-format="pdf"}
#| ref-label: test-plot
#| label: fig-test-pdf
#| fig-cap: Does it work?
#| fig-subcap:
#| - Test A
#| - Test B
#| layout-ncol: 2
:::
The output of this code is in [@fig-test-html]{.content-visible unless-format="pdf"} [@fig-test-pdf]{.content-visible when-format="pdf"}.
The first chunk contains the code that the two others will fetch to produce the figures. The first div shows its content for every format except pdf, and includes the `column-page` option. The second div shows only for PDF and is exactly the same but without the `column-page`, as it crashes the LaTeX render even if the PDF doesn't need it.
A major drawback is that these two chunks can't share the same `label`, so I also needed to use conditional content for inline references: `[@fig-test-html]{.content-visible unless-format="pdf"} ` references the first chunk for every format except pdf, and `[@fig-test-pdf]{.content-visible when-format="pdf"}` references the second chunk for pdf output.
The example above should render properly to both HTML and PDF with `quarto render`.
Bug description
layout-ncol functionality not working
Steps to reproduce