如何在 R markdown 中保留 TABLE "here defnitely"

How to keep a TABLE "here defnitely" in R markdown

我想保留在 rmarkdown 文档中创建的 table 输出为 pdf 的锁定位置,而不是灵活地适应文本。

比如我的代码是:

---
title: "Rest"
author: "Dowdy"
date: "3/23/2019"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
library(stargazer)
library(data.table)
```

Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. 


Hello friend. 


\begin{center}
```{r star, results='asis',echo=F,eval=T, message=FALSE}

star = capture.output(stargazer(data.table(cars)[1:15],digits=3,type = "latex",summary=F,digits.extra = 2,header = F))

star = gsub("& \$([0-9]+)\$", "& \$ 0.000 \$", star)

cat(star)

```
\end{center}

Welcome to my world of toys.  Welcome to my world of toys.Welcome to my world of toys.Welcome to my world of toys.Welcome to my world of toys.Welcome to my world of toys.Welcome to my world of toys.Welcome to my world of toys.Welcome to my world of toys.Welcome to my world of toys.
Welcome to my world of toys.
Welcome to my world of toys. gs I am testing heloo. 
Of all the things I am testing heloo. Of all the things I am testing heloo. Of all the things I am testing heloo. 

Of all the things I am testing heloo. Of all the things I am testing heloo. 

1. Test hi hihhihihih 

2. why is this hiiii

3. why test test test 


4. test test test

不幸的是,输出是这样的:

我不希望图像以这种方式拆分我的编号列表和文本。我希望文本和图像的顺序与我在 rmarkdown 文档中键入的顺序完全相同。具体来说,该编号列表和关于玩具的段落应该全部出现在 table 之后,因为它是在降价中输入的。

对于数字,问题试图做我想做的我相信。当然,我问的是 tables 而不是数字,所以这个解决方案对我没有帮助。

当我更新我的 tex 时我必须检查这个,我可能需要更多关于你想要什么的信息,但是如果你想在文本中间有 table,所有您需要做的是删除 \begin{center}\end{center}。 R 块实际上可以用作任何你想要的复制粘贴,如果你愿意,甚至可以用作 Web 链接。此外,您可以将 knitr 中的 kable() 用于 tables,这有时会有所帮助,有时会使事情变得更糟。等我有更好的互联网时再回来查看。

按照您提供的link中的建议,包括

header-includes:
   - \usepackage{float}

在 YAML header 中。然后,according to the the stargazer manual,你可以用参数table.placement = "H"设置浮动权限,

Places the float at precisely the location in the LaTeX code.

参考:LaTeX/Floats, Figures and Captions

在你的情况下,它将是

star = capture.output(stargazer(data.table(cars)[1:15], digits=3,
                      type = "latex",summary=F,digits.extra = 2,
                      header = F, table.placement = "H"))