kableExtra adding spacing just by loading the package with 2 column kable

48 views Asked by At

I found an oddity that might be a bug, but since I guess it is unlikely to be fixed I am really looking for a workaround. In the below example the tables and image are supposed to be aligned at the top. That works if kableExtra is not loaded, but if it is even loaded (but not used) it adds space above the image. My guess is that it has something to do with the latex packages kableExtra loads but no idea how to debug that or fix it.

Any ideas of a workaround?

---
title: "Gamelist"
editor: visual
params:
  game: Vermeer
  location: dunno
format:
  pdf:
    fig-pos: H
---

```{r}
#| message: false
#| warning: false
#| echo: false
library(tidyverse)
library(rvest)
library(glue)
library(magrittr)
library(knitr)
library(kableExtra)
knitr::opts_chunk$set(echo = FALSE)
```

\vspace{-2.5cm}

some texts

:::: {layout="[50,-2, 50]" layout-valign="top"}


::: {#firstcol}

```{r}
#| results: asis
#| 
for(i in 1:2){
mtcars %>% select(1:4) %>% slice(1:13) %>% kable() %>% print
}

```

:::


::: {#secondcol}


```{r}
download.file("https://www.lemon64.com/assets/images/games/covers/large/vermeer_01.jpg",destfile="cover.jpg",method="curl")
knitr::include_graphics("cover.jpg", dpi = 96)

```

:::


::::

EDIT: As per the suggestion of @Julian I looked into the tex generated. The below packages are loaded with kableExtra. But the important difference seems to be that by default a longtable is used while if kableExtra is loaded a regular table is used. Setting kable(longtable = TRUE) solves the alignment issue.

\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}
0

There are 0 answers