Search code examples
rlatexknitrsweave

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


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} 

Solution

  • 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")