【发布时间】:2021-03-20 10:49:47
【问题描述】:
我正在尝试将此 .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 生成的表格,它会编译为 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}
这个表导致错误怎么办?
编辑,代表:
---
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)
```
【问题讨论】:
-
LaTeX 代码看起来不错。可能缺少一些编译为 PDF 所需的包,但如果没有 (.Rmd) 源,就很难判断。您能否提供一个可重现的最小示例?
-
感谢@M.A.,添加了.Rmd
标签: r r-markdown pdflatex