代码之家  ›  专栏  ›  技术社区  ›  s_baldur

取消R的胶水包装中的新线预防措施

  •  1
  • s_baldur  · 技术社区  · 7 年前

    “可以在行尾使用\\来阻止添加换行” . 在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 \\
    
    1 回复  |  直到 5 年前
        1
  •  0
  •   s_baldur    7 年前

    我发现了一个更好的方法,那就是将LaTeX linebreaks作为变量添加进来,以防止它们被 glue :

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

    输出

    \midrule
    \textbf{3.758} & 820 &  100\% \\
    ~other & 902 \\