rlatexquartokableextratinytex

Adds an header row on top of a table with bold equation using kableExtra and rendering it in quarto


I am making a table with kableExtra version 1.3.4 in a beamer presentation with quarto version 1.4.274 using the following code and installing tinytex version 0.46 with tinytex::install_tinytex():

library(tibble)
library(kableExtra)

payoff_ultimatum <- tibble(participante = c('Receptor', 'Receptor'),
                           oferta = c('Acepta', 'Rechaza'),
                           pagos = c('$((1- \\lambda)N, \\lambda N)$', '$(0,0)$'))

payoff_ultimatum |> 
  kbl(col.names = c('', '', '$\\lambda \\in [0,1]$'), 
      format = 'latex', align = 'c', booktabs = TRUE, 
      escape = FALSE) |>
  kable_styling() |>
  column_spec(column = c(1, 2), bold = TRUE) |> 
  collapse_rows(columns = 1, valign = 'middle') |> 
  add_header_above(header = c(' ' = 2, 'Proponente' = 1),
                   align = 'c',
                   bold = TRUE)

I get the following result:

enter image description here

I want to make bold the header which contains the desire equation like this. I try the following code including in the YALM the related package \usepackage{bm}:

---
format: 
  beamer:
    include-in-header:
      - text: |
          \usepackage{booktabs}
          \usepackage{longtable}
          \usepackage{array}
          \usepackage{multirow}
          \usepackage{wrapfig}
          \usepackage{float}
          \usepackage{colortbl}
          \usepackage{pdflscape}
          \usepackage{tabu}
          \usepackage{threeparttable}
          \usepackage{threeparttablex}
          \usepackage[normalem]{ulem}
          \usepackage{makecell}
          \usepackage{xcolor}
          \usepackage{bm}
---

# Teoría de juegos

```{r}
library(tibble)
library(kableExtra)

payoff_ultimatum <- tibble(participante = c('Receptor', 'Receptor'),
                           oferta = c('Acepta', 'Rechaza'),
                           pagos = c('$((1- \\lambda)N, \\lambda N)$', '$(0,0)$'))

payoff_ultimatum |> 
  kbl(col.names = c('', '', '$\\boldsymbol{\\lambda \\in [0,1]}$'), 
      format = 'latex', align = 'c', booktabs = TRUE, 
      escape = FALSE) |>
  kable_styling() |>
  column_spec(column = c(1, 2), bold = TRUE) |> 
  collapse_rows(columns = 1, valign = 'middle') |> 
  add_header_above(header = c(' ' = 2, 'Proponente' = 1),
                   align = 'c',
                   bold = TRUE)
```

But I get the following error ! Improper alphabetic constant. <to be read again> \mitlambda. I am not and expert in latex but the following code works which is what kableExtra version 1.3.4 and quarto version 1.4.274 are using in relation to the table I am trying to build:

\documentclass{beamer}

\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage{xcolor}
\usepackage{bm}

\begin{document}

\begin{frame}

\frametitle{Teoría de juegos}

\begin{table}
\centering
\begin{tabular}[t]{>{}c>{}cc}
\toprule
\multicolumn{2}{c}{\textbf{ }} & \multicolumn{1}{c}{\textbf{Proponente}} \\
\cmidrule(l{3pt}r{3pt}){3-3}
 &  & $\boldsymbol{\lambda\in[0,1]}$\\
\midrule
 & \textbf{Acepta} & $((1- \lambda)N, \lambda N)$\\
\cmidrule{2-3}
\multirow{-2}{*}{\centering\arraybackslash \textbf{Receptor}} & \textbf{Rechaza} & $(0,0)$\\
\bottomrule
\end{tabular}
\end{table}

\end{frame}

\end{document}

Anyone knows how can I render this table with a bold equation in the header using quarto without getting errors as in the case of latex?


Solution

  • You can try to use poor man's bold: $\\pmb{\\lambda \\in [0,1]}$

    enter image description here