我正在尝试使用RMarkdown中的latex表示法格式化一个表。我的代码如下:
begin{table}[h!]
center
begin{tabular}{l|c|c}
hline
Model & Coefficient & \
Predictors & Value $ p-value\
hline
Intercept & -1.716 & 0.022\
Retire & 0.197 & 0.020\
Age & -0.015 & 0.020\
Health Status & 0.312 & <0.001\
Income & 0.002 & 0.002\
Years of Education & 0.114 & <0.001\
Married & 0.579 & <0.001\
Hispanic & -0.810 & <0.001\
hline
end{tabular}
end{table}
然而,出于某种原因,当我将文档编织在一起时,我会出现以下错误:
You may need to add $ $ around a certain inline R expression `r ` in draft.Rmd (see the above hint). See https://github.com/rstudio/rmarkdown/issues/385 for more info.
Error: LaTeX failed to compile draft.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See draft.log for more info.
Execution halted
当我删除这个块时,它会很好地组合在一起(包括我使用这个方法组合的其他表(,我不知道这个代码发生了什么。任何帮助都会很棒!
两个问题:
-
您有一个
$
而不是&
-
它是
centering
或begin{center}...end{center}
,而不是center
(这种工作只是偶然的(
此外,我建议您查看siunitx
包以获得正确的减号/<标志和细胞的正确排列。此外,booktabs
包可能值得一看,以获得一个好看的表。
documentclass{article}
begin{document}
begin{table}[h!]
centering
begin{tabular}{l|c|c}
hline
Model & Coefficient & \
Predictors & Value & p-value\
hline
Intercept & -1.716 & 0.022\
Retire & 0.197 & 0.020\
Age & -0.015 & 0.020\
Health Status & 0.312 & <0.001\
Income & 0.002 & 0.002\
Years of Education & 0.114 & <0.001\
Married & 0.579 & <0.001\
Hispanic & -0.810 & <0.001\
hline
end{tabular}
end{table}
end{document}