3

在胶水包中,您“可以在行尾使用 \\ 来防止添加换行符”。在 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 \\
4

1 回答 1

0

我发现一个更好的方法是将 LaTeX 换行符添加为一个变量,以防止它们被解释glue

lineb <- '\\\\'
glue_data(
  iris,
  "\\midrule
  \\textbf{{{mean(Petal.Length)}} & 820 &  100\\% {lineb}
  ~other & 902 \\\\"
)

输出

\midrule
\textbf{3.758} & 820 &  100\% \\
~other & 902 \\
于 2018-09-11T11:07:37.703 回答