如何阻止书本表格在pdf中浮动到页面底部? [英] How to stop bookdown tables from floating to bottom of the page in pdf?

查看:10
本文介绍了如何阻止书本表格在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 如下所示:

The resulting pdf looks like this:

为什么表格会移到页面底部?有没有办法防止这种行为?

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.

这篇关于如何阻止书本表格在pdf中浮动到页面底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆