我遇到的问题类似于“ R,knitr 不尊重块和文本的顺序”中提出的问题。在我的代码中,我有一个文本标题,后跟一个块,该块使用四个 knit::kable 函数调用来显示四个表。奇怪的是,在 PDF 输出中,表 1 和表 2 出现在标题上方,表 3 和表 4 出现在下方。看来这与针织物允许物体漂浮有关。我可以最好在 knitr::kable 函数或块选项中关闭它吗?这是我的代码:
---
title: "Reproducible Error"
author: "Rex Macey"
date: "February 14, 2017"
output: pdf_document
header-includes:
- \usepackage{placeins}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\newpage
# Section 1
```{r CompTables, echo=FALSE, warning=FALSE, results='asis', out.extra='FloatBarrier'}
comptables1<-matrix(rep(c(100,200,300,400,500),3),nrow=5,ncol=3)
colnames(comptables1)<-c("Conservative","Moderate","Aggressive")
row.names(comptables1)<-c("5th %-tile","25th %-tile","50th %-tile","75th %-tile","95th %-tile")
comptables2<-matrix(0,nrow=6,ncol=3)
comptables2[1,]<-comptables1[1,]
for (i in 2:5){
comptables2[i,]<-comptables1[i,]-comptables1[i-1,]
}
comptables<-list()
comptables[[1]]<-list(comptables1,comptables2)
comptables[[2]]<-list(comptables1,comptables2)
comptables[[3]]<-list(comptables1,comptables2)
comptables[[4]]<-list(comptables1,comptables2)
knitr::kable(comptables[[1]][1],
caption="Table of Forecast Wealth Values: Suggested …Run Code Online (Sandbox Code Playgroud)