xtable caption alignment left aligned with table or centered (using knitr)

怎甘沉沦 提交于 2019-12-10 18:34:39

问题


I'd like to align an xtable figure caption left adjusted with the table, or if that doesn't work, at least centered, because I think it looks kind of stupid a small table being centered and the corresponding caption being left aligned. Also, left aligning both table and caption is not optimal.

It should be possible using latex.environments = "left", but I get an error message, just like in this post.

I don't think the problem lies in the referencing, because I get the same error message with and without label="myLabel".

Here a MWE:

<<table, echo=FALSE, results='asis'>>=
print(xtable(lm(mpg~hp, data=mtcars), caption="Linear Model", label="myLabel") , caption.placement = "top", latex.environments="left")
@

The error (short form, for long version see this post again):

Missing $ inserted.
Missing delimiter (. inserted)
Missing $ inserted
Missing \right. inserted

Does somebody know a solution? Left aligned with left side of the table or centered, I'd be happy with any solution.


回答1:


Ok so I found a solution to at least center the table captions, using package caption, specifying

\usepackage[
    singlelinecheck=false,
    justification=centering
]{caption}


来源:https://stackoverflow.com/questions/31379658/xtable-caption-alignment-left-aligned-with-table-or-centered-using-knitr

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