Как сохранить СТОЛ "здесь определенно" в уценке R - PullRequest
2 голосов
/ 23 марта 2019

Я хочу, чтобы таблица, созданная в документе 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. В частности, этот нумерованный список и абзац об игрушках должны появляться после таблицы, как это указано в уценке.

Что касается цифр, этот вопрос пытался сделать то, что я хочу сделать, я верю. Конечно, я спрашиваю это для таблиц вместо цифр, поэтому решение не помогает мне.

Ответы [ 2 ]

2 голосов
/ 05 июня 2019

Как указано в предоставленной вами ссылке, включите

header-includes:
   - \usepackage{float}

в заголовке YAML. Затем и в соответствии с руководством stargazer вы можете установить разрешение с плавающей точкой с аргументом table.placement = "H", что

Размещает поплавок точно в том месте, где указан код LaTeX.

Ссылка: LaTeX / Float, рисунки и подписи

В вашем случае это будет

star = capture.output(stargazer(data.table(cars)[1:15], digits=3,
                      type = "latex",summary=F,digits.extra = 2,
                      header = F, table.placement = "H"))
1 голос
/ 24 марта 2019

Мне нужно проверить это, когда я обновлю свой текст, и мне может понадобиться немного больше информации о том, что именно вы хотите, но если вы хотите, чтобы таблица была в середине текста, все, что вам нужно сделать, это удалить \begin{center} и \end{center}. R-фрагменты действительно используются в качестве копировальной пасты, где вы хотите, и даже работают как веб-ссылки, если хотите. Кроме того, вы можете использовать kable() от knitr для таблиц, и это иногда помогает, иногда ухудшает ситуацию. Я проверю позже, когда у меня будет лучший интернет.

...