我试图让xtable
输出显示在小页面中,以及周围的其他文本段落。虽然我的第二个xtable
使用 markdown 显示良好,但第一个只是重复代码段。
知道如何让它工作吗?
---
output:
pdf_document: default
header-includes:
- \usepackage[dvipsnames]{xcolor}
- \usepackage{ragged2e}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \lhead{\textsc{blah blah}}
- \rhead{\textsc{\bfseries \large blah blah}}
- \renewcommand{\footrulewidth}{0.4pt}
- \lfoot{blah blah}
- \fancypagestyle{plain}{\pagestyle{fancy}}
---
\fcolorbox{Fuchsia}{Fuchsia}{\begin{minipage}{46.5em}\centering\textbf{\large\color{white}ABOUT THIS TEST}\end{minipage}}
\offinterlineskip
\fbox{\begin{minipage}[t]{46.5em}
\vspace*{0.3cm}\centering\textbf{METHODOLOGY}\vspace*{0.3cm}
\justify blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah \vspace*{0.3cm}
\justify blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah \vspace*{0.3cm}
<<echo=FALSE, results=tex>>=
library(xtable)
print(xtable(head(mtcars)), floating = FALSE, include.rownames = FALSE)
@
\end{minipage}}
\bigskip
**Table 1.** Blah blah blah Blah blah blah Blah blah blah Blah blah blah Blah
```{r, xtable, results = 'asis', echo=FALSE, eval=TRUE, message=FALSE}
library(xtable)
x <- head(mtcars)
print(
xtable(x, caption = 'Blah Blah'), caption.placement = 'top',
include.colnames = FALSE, comment = FALSE
)
```
答案1
您不能result=tex
在使用该语法的 R markdown 中的 R 块中使用 Sweave 选项knitr
,但更重要的是,您不能对 noweb () 文件使用 R 块语法.Rnw
。也就是说,一些像:
<<name,results='asis', option, option, ...>>=
2+2
@
即使块位于 LaTeX 环境中,仍然是错误的。相反,您必须始终使用 R markdown 语法:
```{r name, results='asis', option, option, ...}
2+2
```
在下面的 MWE 中,LaTeX、R 和 markdown 中还有许多其他与问题无关的更改,以简化示例(删除标题等)和代码(instead of a minipage,etc.) or style suggestions (booktabs
表格规则的 tcolorbox 等)。结果:
---
header-includes:
- \usepackage[most]{tcolorbox}
- \usepackage{caption}
- \usepackage{parskip}
- \usepackage{booktabs}
output:
pdf_document: default
---
\begin{tcolorbox}[colbacktitle=blue!85!red!60,
fonttitle=\bfseries\sffamily\centering,
colback=green!05,boxsep=1mm,arc=0mm,boxrule=1pt,
title=ABOUT THIS TEST]\parskip1em
\subsection*{\centering METHODOLOGY}
Blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah.
Blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah.
\centering
\captionof{table}{The head of mtcars}
```{r table, echo=F,results="asis"}
library(xtable)
x <- head(mtcars)
print(xtable(x, digits=c(0,1,0,0,0,2,2,2,0,0,0,0),align="lccccccccccc"),
floating = F, include.rownames = T,booktabs=T)
```
\end{tcolorbox}
```{r xtable, results = 'asis', echo=F}
print(xtable(x, caption="Blah blah Blah blah blah Blah blah blah."),
caption.placement = 'top', include.colnames = F, comment = F )
```