导致rmarkdown失败的stargazer输出
我正在尝试将此.rmd编译为pdf,但我不断收到一个错误:导致rmarkdown失败的stargazer输出,r,r-markdown,pdflatex,R,R Markdown,Pdflatex,我正在尝试将此.rmd编译为pdf,但我不断收到一个错误: ! LaTeX Error: \caption outside float. Error: LaTeX failed to compile 2020-07-23_a.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See 2020-07-23_a.log for more info. Execution halted 如果我删除stargazer
! LaTeX Error: \caption outside float.
Error: LaTeX failed to compile 2020-07-23_a.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See 2020-07-23_a.log for more info.
Execution halted
如果我删除stargazer生成的此表,它将编译为pdf:
% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Tue, Dec 08, 2020 - 10:50:52 PM
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}} ccccccccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
& a & d & e & f & g & h & i & j \\
\hline \\[-1.8ex]
1 & a & $0.190$ & $1.314$ & $$-$7$ & $1$ & $1,047.041$ & $$-$14.031$ & $$-$146.912$ \\
2 & b & $0.168$ & $1.484$ & $$-$1$ & $1$ & $997.999$ & $$-$5.740$ & $$-$57.288$ \\
3 & c & $0.242$ & $1.033$ & $$-$4$ & $0$ & $974.519$ & $$-$6.615$ & $$-$64.467$ \\
4 & d & $0.245$ & $1.021$ & $$-$3$ & $1$ & $997.918$ & $$-$8.568$ & $$-$85.500$ \\
\hline \\[-1.8ex]
\end{tabular}
\end{table}
这个表会导致错误吗
编辑,reprex:
---
title: "Test"
author: ''
editor_options:
chunk_output_type: console
output:
pdf_document:
fig_caption: yes
fig_height: 10
fig_width: 15
toc: yes
toc_depth: 3
word_document:
toc: yes
toc_depth: '3'
html_document:
fig_caption: yes
fig_height: 10
fig_width: 15
toc: yes
toc_depth: '2'
geometry: margin=0.9in
header-includes:
- \usepackage{fancyhdr}
- \usepackage{color}
- \usepackage{lipsum}
- \hypersetup{linkcolor=blue}
- \pagestyle{fancy}
- \fancyhf{}
- \lhead{`r Sys.Date()`}
- \renewcommand{\headrulewidth}{0.5pt}
- \rfoot{\thepage}
- \lfoot{\hyperlink{page.1}{$\Uparrow$}}
- \fancypagestyle{plain}{\pagestyle{fancy}}
- \setcounter{totalnumber}{1}
fontsize: 6pt
classoption: landscape
---
<!--
Comments
Version: 2017-06-05
-->
```{r, echo=FALSE, results='asis'}
tblSummary =structure(list(a = c("a", "b", "c", "d"), d = c(0.190284983522521,
0.168477173924889, 0.242036289808836, 0.244817676726466), e = c(1.31381885933427,
1.48388054106045, 1.03290295929364, 1.02116809269179), f = c(-7,
-1, -4, -3), g = c(1, 1, 0, 1), h = c(1047.04137748695, 997.998686454919,
974.519473047256, 997.918457406374), i = c(-14.0312028883339,
-5.74023801609359, -6.61528084178918, -8.56783431205567), j = c(-146.9125,
-57.2875, -64.4672, -85.5)), class = "data.frame", row.names = c(NA,
-4L))
stargazer::stargazer(tblSummary, summary = FALSE)
```
---
标题:“测试”
作者:''
编辑器选项:
块输出类型:控制台
输出:
pdf\U文件:
图片说明:是的
fig_高度:10
图u宽度:15
toc:是的
toc_深度:3
word_文件:
toc:是的
toc_深度:“3”
html_文件:
图片说明:是的
fig_高度:10
图u宽度:15
toc:是的
toc_深度:“2”
几何图形:边距=0.9英寸
标题包括:
-\usepackage{fancyhdr}
-\usepackage{color}
-\usepackage{lipsum}
-\hypersetup{linkcolor=blue}
-\pagestyle{fancy}
-\fancyhf{}
-\lhead{`r Sys.Date()`}
-\renewcommand{\headrulewidth}{0.5pt}
-\rfoot{\thepage}
-\lfoot{\hyperlink{page.1}{$\Uparrow$}
-\fancypagestyle{plain}{\pagestyle{fancy}
-\setcounter{totalnumber}{1}
字体大小:6磅
类别选项:景观
---
```{r,echo=FALSE,results='asis'}
TBL摘要=结构(列表a=c(“a”、“b”、“c”、“d”),d=c(0.190284983522521,
0.168477173924889,0.242036289808836,0.244817676726466),e=c(1.31381885933427,
1.48388054106045,1.03290295929364,1.02116809269179),f=c(-7,
-1,-4,-3),g=c(1,1,0,1),h=c(1047.041377486959997.998686454919,
974.519473047256,997.918457406374),i=c(-14.031202888339,
-5.74023801609359,-6.61528084178918,-8.56783431205567),j=c(-146.9125,
-57.2875,-64.4672,-85.5),class=“data.frame”,row.names=c(NA,
-(4升)
stargazer::stargazer(TBL摘要,摘要=FALSE)
```
一个选项是将输出标记为:
```{r, results = 'asis', echo = F}
cat("```{=latex}")
stargazer( tblSummary, summary = FALSE,type = "latex", header = FALSE)
cat("```")
```
乳胶代码看起来不错。可能缺少编译为PDF所需的一些包,但如果没有(.Rmd)源代码,则很难判断。你能提供一个最小的可重复的例子吗?谢谢@M.a.,添加了.Rmd