How to render two different tables with Elsevier extension in quarto? #13084
Replies: 6 comments 27 replies
-
Could you remove pieces of your code one by one to end up with something small? Preferably something that does both require external dependencies such as janitor. Also, please if we don't need the 100+ packages from the tidyverse, please don't include I'm assuming the extension is the one that can be installed with Thank you for your help! |
Beta Was this translation helpful? Give feedback.
-
Yes, you were correct in assuming I was referring to the extension that can be installed with I took the example you provided and modified the code for the second table to create the output I was having problems with. The issue was with the html code contained in the second table of my original post. I added a comment to indicate the location in the code below. I originally wrote the code to render as a docx before I realized there was an extension available. I used the html code to italicize some text in the table headers. If the html code is removed from the second table below, the document will render correctly, but it seems to create two other problems. One, I still need to italicize some text in the table headers, but I don't know how to achieve that using the extension. Second, the second table is rendered wider than the page and I don't know if there are options to adjust the table and still be able to use the extension. ---
title: Imaginary title
author:
- name: FirstName LastName
email: email@address
abstract: |
{{< lipsum 1 >}}
format:
elsevier-pdf: default
execute:
echo: false
warning: false
---
# Introduction
```{r}
#| label: r-libraries
library(gt)
data(penguins)
```
```{r}
#| label: tbl-data1
#| tbl-cap: Table caption for data set one.
#| tbl-pos: "!h"
gt(head(penguins, c(5L, 5L)))
```
```{r}
#| label: tbl-data2
#| tbl-cap: This table shows information for two variables.
#| tbl-pos: "!h"
males <- penguins |>
dplyr::filter(island == 'Torgersen' & sex == 'male' & year == 2007) |>
head(c(4L, 4L))
females <- penguins |>
dplyr::filter(island == 'Torgersen' & sex == 'female' & year == 2007) |>
head(c(4L, 4L)) |>
dplyr::select(bill_len, bill_dep)
first_four <- penguins |>
dplyr::filter(island == 'Torgersen' & year == 2007) |>
head(c(4L, 4L)) |>
dplyr::select(bill_len, bill_dep)
peng_tbl <- cbind(males, females, first_four) |>
janitor::clean_names() |>
gt() |>
tab_spanner(label = 'Male', columns = c('bill_len', 'bill_dep')) |>
tab_spanner(label = 'Female', columns = c('bill_len_2', 'bill_dep_2')) |>
tab_spanner(label = 'M + F', columns = c('bill_len_3', 'bill_dep_3')) |>
cols_label(
# note the html in the line below that is creating the problem
bill_len_2 = html('<em>bill_len</em>'),
bill_dep_2 = 'bill_dep',
bill_len_3 = 'bill_len',
bill_dep_3 = 'bill_dep')
peng_tbl
```
|
Beta Was this translation helpful? Give feedback.
-
Thank you. As I stated, I was originally rendering to a docx, and I didn't realize the nuances between HTML and LaTeX when trying to create the pdf that required a modification. You have provided a very simple solution to the first problem I mentioned. As for the complication of the example, I don't see how to make it simpler with my code experience because I need a table that is multiple columns wide or at least wider than the table you created in your example to illustrate how it does not fit the page. I'm sure there is a more elegant way to create the wide table, but nonetheless, I needed a wider table. Landscape orientation could solve the problem, but this was not necessary when I originally rendered to a docx. I also tried ---
title: Imaginary title
author:
- name: FirstName LastName
email: email@address
abstract: |
{{< lipsum 1 >}}
format:
elsevier-pdf: default
execute:
echo: false
warning: false
---
# Introduction
```{r}
#| label: r-libraries
library(gt)
data(penguins)
```
```{r}
#| label: tbl-data2
#| tbl-cap: This table shows information for two variables.
#| tbl-pos: "!h"
males <- penguins |>
dplyr::filter(island == 'Torgersen' & sex == 'male' & year == 2007) |>
head(c(4L, 4L))
females <- penguins |>
dplyr::filter(island == 'Torgersen' & sex == 'female' & year == 2007) |>
head(c(4L, 4L)) |>
dplyr::select(bill_len, bill_dep)
first_four <- penguins |>
dplyr::filter(island == 'Torgersen' & year == 2007) |>
head(c(4L, 4L)) |>
dplyr::select(bill_len, bill_dep)
peng_tbl <- cbind(males, females, first_four) |>
janitor::clean_names() |>
gt() |>
tab_spanner(label = 'Male', columns = c('bill_len', 'bill_dep')) |>
tab_spanner(label = 'Female', columns = c('bill_len_2', 'bill_dep_2')) |>
tab_spanner(label = 'M + F', columns = c('bill_len_3', 'bill_dep_3')) |>
cols_label(
bill_len_2 = md('*bill*_len'),
bill_dep_2 = 'bill_dep',
bill_len_3 = 'bill_len',
bill_dep_3 = 'bill_dep')
peng_tbl
``` |
Beta Was this translation helpful? Give feedback.
-
The previous example you provided will not work for me if I render the document. If I run each chunk individually, I can see the table output if I omit the Quarto 1.6.42
attached base packages: other attached packages: loaded via a namespace (and not attached): |
Beta Was this translation helpful? Give feedback.
-
Ok, It has actually nothing to do with the Elsevier extension, the use of Markdown or HTML inside the table. ---
format: pdf
---
```{r}
#| label: tbl-label-matters
library(gt)
data(penguins)
gt(head(penguins, c(5L, 5L))) |>
tab_spanner(label = "species_spanner", columns = c("species")) |>
as_raw_html()
``` (can't dive more into it now) |
Beta Was this translation helpful? Give feedback.
-
TL;DR from #13084 (reply in thread) ---
format: pdf
---
::: {#tbl-label tbl-cap='Caption'}
```{=html}
<table>
<thead>
<tr><th rowspan="2">island</th></tr>
<tr></tr>
</thead>
</table>
```
::: From this, to avoid LaTeX crash, do any:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
The code below uses the Elsevier journal extension (which must be installed) to create two tables. The first table created in a chunk labelled @tbl-data1 works as expected. The code for the second table labelled @tbl-data2 fails. The code for the second table is currently commented out using
{{r}}
. The document below will render unless the code for the second table is changed to{r}
.When I try to render both tables in the document, I get the following error:
ERROR:
compilation failed- error
Undefined control sequence.
l.207 \multirow
{2}{=}{\begin{minipage}[b]{\linewidth}\raggedright
The tables are made differently. Table 1 has one column under each header column. Table 2 has two columns under each header column, which seems to be causing the problem during rendering. Does anyone know a solution that will allow both tables to render?
Beta Was this translation helpful? Give feedback.
All reactions