How do I insert a line break in an xtable caption?

≯℡__Kan透↙ 提交于 2020-02-02 13:37:00

问题


I'm sure it's a simple solution but Ive been searching all day trying to solve this. All I want to do is split an xtable caption over 2 lines. I've tried \n and caption.width to no avail.

\documentclass{article}

\usepackage{caption}

\begin{document}

<<makedata,echo=TRUE,results='asis'>>=
df <- matrix(round(rnorm(9, 20, 10)), 3, 3)
colnames(df) <- c("Column1","Column2","Column3")
require(xtable)
print (xtable(df, caption="Title1\nTitle2"),caption.placement="top")
@




\end{document} 

回答1:


I think you need \\\\ so that it will print out in the tex file as \\ which creates a line break.

print (xtable(df, caption="Title1\\\\Title2"),caption.placement="top")



回答2:


Sam's answer led me in the right direction, but I had to use \\newline instead of \\\\ since I was getting latex errors about overflowed boxes. Maybe the difference is that I'm generating my captions dynamically:

title <- paste("some text","\\newline",sep='')
print(xtable(df, caption=title))


来源:https://stackoverflow.com/questions/19937904/how-do-i-insert-a-line-break-in-an-xtable-caption

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