How do I stop table tables from floating at the bottom of the page in pdf format?
I use bookdown
to generate pdf reports, but my tables all float down to the bottom of the page, no matter how much space is there. See this example:
---
title: "test_doc"
author: "Jake Thompson"
date: "6/30/2017"
output:
bookdown::pdf_document2:
toc: false
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, collapse = TRUE)
library(tidyverse)
```
# Test heading
Let make a data frame and print it in Table \@ref(tab:test-table)
```{r test-table}
data_frame(col_a = seq_len(5), col_b = rnorm(5), col_c = runif(5)) %>%
knitr::kable(caption = "This is a test")
```
The resulting pdf looks like this:
Why is the table at the bottom of the page? And is there a way to prevent this behavior?
+3
source to share
1 answer
You can solve this problem with kableExtra
on
data_frame(col_a = seq_len(5), col_b = rnorm(5), col_c = runif(5)) %>%
knitr::kable(caption = "This is a test") %>%
kableExtra::kable_styling(latex_options = "hold_position")
Basically it inserts [!h]
into LaTeX environment table
which will prevent floating behavior and will output the table to the current location.
+1
source to share