如何在R markdown中保持一个“这里肯定”

问题描述 投票:2回答:2

我想保留一个在rmarkdown文档中创建的表格,该文档输出到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

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

enter image description here

我不希望图像以这种方式分割我的编号列表和文本。我希望文本和图像的顺序与我在rmarkdown文档中输入的顺序完全一样。具体而言,该编号列表和关于玩具的段落应该在表格之后全部出现,因为它是在降价时输入的。

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

r latex r-markdown knitr figure
2个回答
2
投票

正如您提供的链接中所示,包括

header-includes:
   - \usepackage{float}

在YAML标题中。然后,和according to the the stargazer manual一起,您可以使用参数table.placement = "H"设置float权限

将浮动放置在LaTeX代码中的精确位置。

参考: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"))

1
投票

当我更新我的tex时,我必须检查这一点,我可能需要更多关于你想要的信息,但是如果你想把表放在文本的中间,你需要做的就是删除\begin{center}\end{center}。 R块实际上可以用作任何你想要的复制粘贴,甚至可以用作网络链接。另外,你可以使用knitr的kable()作为表格,这有时会让事情变得更糟。当我有更好的互联网时,我会稍后再查看。

© www.soinside.com 2019 - 2024. All rights reserved.