如何停止Bookdown表格从pdf浮动到页面底部? [英] How to stop bookdown tables from floating to bottom of the page in pdf?
本文介绍了如何停止Bookdown表格从pdf浮动到页面底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用bookdown
创建pdf报告,但是无论表有多少空间,我的表都向下浮动到页面底部.参见以下示例:
I am using bookdown
to create pdf reports, but my tables are all floating down to the bottom of the page, regardless of how much space there is. 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")
```
生成的pdf如下:
为什么表格会转到页面底部?有没有办法防止这种行为?
Why does the table go to the bottom of the page? And is there a way to prevent this behavior?
推荐答案
您可以使用kableExtra
解决此问题,
You can solve this problem with kableExtra
by
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")
它基本上将[!h]
插入LaTeX table
环境,这将防止浮动行为并将表固定在当前位置.
It basically insert a [!h]
to the LaTeX table
environment which will prevent the floating behavior and pin the table at current location.
这篇关于如何停止Bookdown表格从pdf浮动到页面底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文