【发布时间】:2019-02-12 23:23:00
【问题描述】:
在胶水包中,您“可以在行尾使用 \\ 来防止添加换行符”。在 LaTeX 中 \\ 是换行符。
我正在寻找比当前解决方案更好的解决方案
glue_data(iris,
"\\midrule
\\textbf{{{mean(Petal.Length)}} & 820 & 100\\% \\\\
~other & 902 \\\\"
)
实际输出:
\midrule
\textbf{3.758} & 820 & 100\% \~other & 902 \\
预期输出:
\midrule
\textbf{3.758} & 820 & 100\% \\
~other & 902 \\
我目前的丑陋和容易出错的修复:
glue_data(iris,
"\\midrule
\\textbf{{{mean(iris$Petal.Length)}} & 820 & 100\\% \\\\\\
\n~other & 902 \\\\"
)
\midrule
\textbf{3.758} & 820 & 100\% \\
~other & 902 \\
【问题讨论】:
-
glue_data似乎不适用于 LaTeX。为什么不使用其他方式将计算值插入 LaTeX(例如 knitr Rnw 文件)或其他用于宏替换的函数? -
好点@user2554330。我喜欢胶水的整体语法,并决定尝试这个项目。无论如何,我已经找到了对我当前解决方案的改进,它将换行符作为变量传递,因此胶水不会解释它们:
lineb <- '\\\\'然后... & 100\\% {lineb} -
您应该添加您的
{lineb}解决方案作为您自己问题的答案。它看起来很聪明。 -
在 `\` 之后但在换行符之前的空格似乎也可以完成这项工作。
标签: r r-markdown knitr r-glue