R gt软件包:乳胶错误(“此处无行可结束") [英] R gt package: error in latex ("there's no line here to end")

查看:86
本文介绍了R gt软件包:乳胶错误(“此处无行可结束")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在tex文件中包含使用gt()函数生成的表.我创建一个.Rnw文件,然后使用knitr进行编织,并使用pdflatex进行编译.在编译过程中,我收到一个错误:这里没有行结束",这是由表头中的gt()插入换行符引起的.这是MWE:

I am trying to include a table generated with the gt() function in a tex file. I create a .Rnw file, then weave it with knitr and compile with pdflatex. During compilation I get an error: "there no line here to end", caused by a newline inserted by gt() in the table header. This is a MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{caption}

\begin{document}
<<setup, include=FALSE>>=
library(knitr)
library(tidyverse)
library(gt)
opts_chunk$set(echo=FALSE)
@

This is a dataframe formatted with the \texttt{gt} package.

<<>>=
tibble(
  group=rep(c("A", "B"), each=5),
  age = c(20, 24, 22, 27, 29, 21, 24, 23, 30, 31)) %>%
    gt %>%
      tab_header(title="Some title")
@

\end{document}

tex文件中的结果表为:

The resulting table in the tex file is:

\begin{longtable}{lr}
\caption*{
\large Some title\\ 
\small \\ % This newline causes the error
} \\ 
\toprule
group & age \\ 
\midrule
A & 20 \\ 
A & 24 \\ 
A & 22 \\ 
A & 27 \\ 
A & 29 \\ 
B & 21 \\ 
B & 24 \\ 
B & 23 \\ 
B & 30 \\ 
B & 31 \\ 
\bottomrule
\end{longtable}

(我在编织后手动添加了评论)

(I added the comment manually after weaving)

由于标题中的换行符(\\),我得到:./mwe.tex:69: LaTeX Error: There's no line here to end.如果没有该换行符,则将按预期方式创建PDF.有没有一种方法可以解决此问题而无需手动编辑tex文件?

Because of the newline (\\) in the caption I get: ./mwe.tex:69: LaTeX Error: There's no line here to end. Without that newline, the PDF is created as expected. Is there a way to fix this without having to manually edit the tex file?

推荐答案

我发现,当未定义字幕时,这是gt发生的错误. 解决方法是 1)添加一个空格作为字幕,或者

I found that it is a bug of gt happening when there is no subtitle is defined. The work around is 1) adding a space as a subtitle, or

tab_header(title = md("Data listing from **gtcars**"), subtitle = md("&nbsp;"))

2)手动编辑tex文件 删除登录表中的\small \\.

2) manually edit the tex file removing \small \\ in the logntable.

在以下位置查看问题 https://github.com/rstudio/gt/issues/197

Check the issue at https://github.com/rstudio/gt/issues/197

这篇关于R gt软件包:乳胶错误(“此处无行可结束")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆