【问题标题】:R markdown won't compile a piece of LaTeX codeR markdown 不会编译一段 LaTeX 代码
【发布时间】:2017-03-12 00:35:27
【问题描述】:

我有以下代码,我想运行 I 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 markdown 不能编译上面的吗?

【问题讨论】:

    标签: r r-markdown


    【解决方案1】:

    通过逐行添加表格代码并每次重新编译,我将问题与插入符号的行隔离开来,例如读取 cyl &amp; -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}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-07
      • 2015-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多