Problems rendering table using r Markdown, kable and kableExtra

[亡魂溺海] 提交于 2020-03-19 06:25:33

问题


I am attempting to output a latex table using r markdown, kable and kableExtra. I get an error in the table rendering code that is not part of the latex code produced by R.

The code:

outTab <- m.OutTab %>%
    kable(format='latex',  booktabs=T ,
          #caption = "Population Trend",
          digits=1, 
          row.names=FALSE, 
          align='lccccc', 
          col.names = names_spaced,
          escape = FALSE)

where "m.OutTab" is an matrix that contains the table to be rendered,

The error:

Error producing PDF.
! Misplaced \noalign.
\addlinespace ->\noalign 
                         {\ifnum 0=`}\fi \@ifnextchar [{\@addspace }{\@addsp...
l.116    \addlinespace

Error: pandoc document conversion failed with error 43

These codes ("\noalign ...") is not part of "outTab".

Any idea how to work around this error?


回答1:


If you are using bookdown, this could be caused by using non-alphanumeric characters in your code chunk label. I had a similar problem which was solved by removing an underscore.




回答2:


I have encountered this problem. I seem to be able to fix it by specifying format="pandoc" or format="markdown". If seems to be some issue with how latex output from kable is handled.




回答3:


It seems like this question is getting a lot of traffic. If you see an error like that, that means that there are something wrong with the raw latex you wrote. Check special symbols like < \ / [] and make sure they are properly escaped by yourself.

Due to running mechanism, a lot of places with kableExtra requires double escape, which means that you need to type \\\\ to get a \. You should be able to get it work after a few attempts.




回答4:


I had a similar issue, although my error message was slightly different:

! Misplaced \noalign.
\addlinespace ->\noalign 
                     {\ifnum 0=`}\fi \@ifnextchar [{\@addspace }{\@addsp...
l.376 \end{tabu}
Error: Failed to compile

In my case, adding

format = "latex"

and

full_width = FALSE

solved it.



来源:https://stackoverflow.com/questions/47704876/problems-rendering-table-using-r-markdown-kable-and-kableextra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!