【问题标题】:Stargazer output in RMarkdown - What is my illegal charachter?RMarkdown 中的 Stargazer 输出 - 我的非法字符是什么?
【发布时间】:2019-12-02 13:47:48
【问题描述】:

我正在运行逻辑回归模型并尝试在 RMarkdown 中使用 stargazer 打印输出。我已经在我的设置中应用了 dcolumn,但是当我尝试将文档编织为 pdf 时,我仍然得到“!LaTeX 错误:数组 arg 中的非法字符。”。我试图只复制 LateX 代码,但它也说我有一个非法字符。有人可以帮我找到非法字符吗?

RMarkdown 文件:

title: "Tables and Figures"
author: "me"
date: "November 2019"
header_includes: - \usepackage{dcolumn}
output: pdf_documentclassoption: landscape




 ```   
 {r Regression results Q21 1, results='asis', echo=FALSE}

 Q21e_teaching99 <- glm(Q21e_teaching ~ Country + Field + typeposition + Gender + Age, data = 
 SurveyPHEC, family = binomial(link = "probit"))

 stargazer(Q21e_teaching99,  type="latex", align = TRUE)

 ```

这产生的LatexCode:

  length of NULL cannot be changedlength of NULL cannot be changedlength of NULL cannot be 
  changedlength of NULL cannot be changedlength of NULL cannot be changed
 % Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at 
 fas.harvard.edu
 % Date and time: man., des 02, 2019 - 14.33.50
 % Requires LaTeX packages: dcolumn 
 \begin{table}[!htbp] \centering 
 \caption{} 
 \label{} 
 \begin{tabular}{@{\extracolsep{5pt}}lD{.}{.}{-3} } 
 \\[-1.8ex]\hline 
 \hline \\[-1.8ex] 
 & \multicolumn{1}{c}{\textit{Dependent variable:}} \\ 
\cline{2-2} 
\\[-1.8ex] & \multicolumn{1}{c}{Q21e\_teaching} \\ 
\hline \\[-1.8ex] 
CountryNorway & -0.255 \\ 
& (0.184) \\ 
& \\ 
CountryUnited Kingdom & 0.046 \\ 
& (0.195) \\ 
& \\ 
CountryNetherlands & 0.322^{**} \\ 
& (0.149) \\ 
& \\ 
CountryDenmark & 0.171 \\ 
& (0.165) \\ 
& \\ 
FieldPhysics & -0.109 \\ 
& (0.124) \\ 
& \\ 
typepositionSenior & 0.912^{***} \\ 
 & (0.119) \\ 
 & \\ 
GenderMale & 0.002 \\ 
 & (0.150) \\ 
 & \\ 
Age40 to 49 years & 0.283 \\ 
 & (0.179) \\ 
 & \\ 
Age50 to 59 years & 0.329^{*} \\ 
 & (0.185) \\ 
 & \\ 
Age60 years and more & 0.610^{***} \\ 
 & (0.192) \\ 
 & \\ 
Constant & -1.548^{***} \\ 
 & (0.217) \\ 
 & \\ 
\hline \\[-1.8ex] 
Observations & \multicolumn{1}{c}{788} \\ 
Log Likelihood & \multicolumn{1}{c}{-326.114} \\ 
Akaike Inf. Crit. & \multicolumn{1}{c}{674.227} \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 
length of NULL cannot be changedlength of NULL cannot be changedlength of NULL cannot be 
changedlength 
of NULL cannot be changedlength of NULL cannot be changed

R Markdown 输出

! LaTeX 错误:数组 arg 中有非法字符。

【问题讨论】:

  • 你能显示完整的 .tex 和 .log 文件吗?如果我猜几个包,我可以编译你的代码片段
  • 标题看起来很可疑。可能需要几个换行符?
  • 感谢您的回复。通过标题,您是指“NULL的长度不能改变NULL的长度不能改变NULL的长度不能改变NULL的长度不能改变NULL的长度不能改变”?
  • 我指的是像output: pdf_documentclassoption: landscape这样的标题
  • 啊,这就是为什么我有一些巨大的表格并设置标题以生成横向格式的 pdf。

标签: pdf latex r-markdown stargazer


【解决方案1】:

错误表示dcolumn包没有加载。未加载的原因是您的 yaml 标头中存在多个语法错误。

以下标头应加载包(注意添加的换行符):

---
title: "Tables and Figures"
author: "me"
date: "November 2019"
output:
  pdf_document:
    keep_tex: true
header-includes:
   - \usepackage{dcolumn}    
classoption: landscape
---

【讨论】:

    猜你喜欢
    • 2021-03-20
    • 1970-01-01
    • 2015-08-04
    • 2018-10-19
    • 2021-06-25
    • 2015-03-04
    • 2011-11-02
    • 2014-06-24
    相关资源
    最近更新 更多