我有以下代码,我想运行我R markdown。我试图在LaTeX编译器中运行它,它工作得非常好。但是当我将它添加到R markdown时,它不会编译这段代码。
---
title: "Titre"
date: Fecha
output:
pdf_document:
keep_tex: true
includes:
in_header: mystyle.sty
---
\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}{mpg} \\
\hline \\[-1.8ex]
cyl & -2.876^{***} \\
& (0.322) \\
& \\
Constant & 37.885^{***} \\
& (2.074) \\
& \\
\hline \\[-1.8ex]
Observations & \multicolumn{1}{c}{32} \\
R$^{2}$ & \multicolumn{1}{c}{0.726} \\
Adjusted R$^{2}$ & \multicolumn{1}{c}{0.717} \\
Residual Std. Error & \multicolumn{1}{c}{3.206 (df = 30)} \\
F Statistic & \multicolumn{1}{c}{79.561$^{***}$ (df = 1; 30)} \\
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
\end{table}
mystyle.sty 文件包含以下内容
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\usepackage{booktabs}
\newcommand{\mc}[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\usepackage{verbatim}
是否有人可以解释为什么R降价可以编译上面的内容?
答案 0 :(得分:2)
通过逐行添加表格代码并每次重新编译,我将问题隔离到带有插入符的行,例如:读取cyl & -2.876^{***} \\
的行。
我能够通过将上标部分括在两个$
符号中来编译文档,即
cyl & -2.876$$^{***}$$ \\
(我不知道为什么你需要两个,而不仅仅是一个$
。)
编译得很好:
---
title: "Titre"
date: Fecha
output:
pdf_document:
keep_tex: true
includes:
in_header: mystyle.sty
---
\begin{table}[!htbp] \centering
\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}{mpg} \\
\hline \\[-1.8ex]
cyl & -2.876$$^{***}$$ \\
& (0.322) \\
& \\
Constant & 37.885$$^{***}$$ \\
& (2.074) \\
& \\
\hline \\[-1.8ex]
Observations & \multicolumn{1}{c}{32} \\
R$^{2}$ & \multicolumn{1}{c}{0.726} \\
Adjusted R$^{2}$ & \multicolumn{1}{c}{0.717} \\
Residual Std. Error & \multicolumn{1}{c}{3.206 (df = 30)} \\
F Statistic & \multicolumn{1}{c}{79.561$^{***}$ (df = 1; 30)} \\
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
\end{table}