在R Markdown中创建可填充的彩色文本框(PDF)

时间:2018-06-22 10:10:21

标签: r pdf r-markdown

我正在尝试创建一个markdown,其中伴随绘图和表格的文本在深蓝色框中,就像下面的图像一样: enter image description here

我尝试查看this solution,但是我完全无法复制该框,当然也不能复制彩色版本。有谁知道如何在降价促销中做到这一点?

---
title: "Untitled"
author: "Test"
date: "22/6/2018"
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)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

\begin{Form}
    \TextField[width = 10cm, height = 10cm]{This is the textbox.}
    I would like a dark blue textbox with white writing
\end{Form}

1 个答案:

答案 0 :(得分:2)

\TextField命令采用一些可选参数来定义颜色和默认文本:

---
output: 
  pdf_document:
    keep_tex: yes
---

\begin{Form}
    \TextField[width = 10cm,%
               height = 3cm,%
               multiline=true,%
               bordercolor = 0 0 0.5,%
               backgroundcolor = 0 0 0.5,%
               color = 1 1 1,%
               value = {%
                          This is the textbox.
                          I would like a dark blue textbox with white writing
                        }%
               ]{}
\end{Form}

这将产生:

enter image description here

一个人可以编辑\TextField以包含多行文本,但是我无法设置多行的value。使用\string\n(参见https://tex.stackexchange.com/questions/416218/how-to-add-line-breaks-to-hyperref-pdf-form-textfield)对我不起作用。不过,这可能取决于PDF查看器。我正在使用Evince。