0

I am using knitr and xtable to generate a table and I would like to wrap some text. The code is below. I would like to wrap the 3rd column (Exposure Groups). The column width looks ok but the text are not wrapped. What is wrong with the code?

TableSumStatsAllPeriods <- xtable(reduced.res.Q4000.THC,
                      caption="Summary statistics ",
                      label="TableSumStatsAllPeriods",
                      align = "llp{4cm}cccccc")

@

\newpage \begin{landscape}

<<printTableSumStatsAllPeriods, echo = FALSE, eval=TRUE,results = "asis" >>=
print(TableSumStatsAllPeriods,tabular.environment='longtable',floating=FALSE,
  caption.placement="top",
  size="small",
  h.line.after=c(-1,nrow(TableSumStatsAllPeriods)),
  add.to.row=list(pos=list(0),command="\\hline \\endhead"))

@ \end{landscape}

example table

mathematical.coffee
  • 55,977
  • 11
  • 154
  • 194
Amateur
  • 1,247
  • 6
  • 20
  • 30
  • 2
    A reproducible example would be fantastic! (also I can't tell from the pic but is each entry in your 'Exposure Groups' column just one word (i.e. no spaces)?) – mathematical.coffee Apr 03 '13 at 05:26
  • I would like to wrap the text in Exposure Group column for each row. If i were to do it in excel, I would just highlight the Exposure Group column and wrap text and that will do it. – Amateur Apr 03 '13 at 06:06
  • 1
    @Amateur: Even though the 3rd column is defined with specification `p{4cm}` and should therefore be only `4cm` wide, it will only break at the designated breakpoints. If you don't have any (using periods between words don't make them breakable), then there's no way for LaTeX to know where to break the line. Is this the case? – Werner Apr 03 '13 at 06:13
  • I tried labels without periods and it still did not wrap the text. – Amateur Apr 03 '13 at 14:57
  • @Werner: You are right about using periods between words that is causing the problems. THank you. – Amateur Apr 03 '13 at 22:46
  • @Amateur: If you have a means to tap into the column entries called "Exposure Groups", then you can modify them accordingly. If this forms part of an automated output, alternatives should be considered. On the LaTeX-side of things, this is definitely possible. However, I don't know how to do this using knitr and/or xtable. – Werner Apr 03 '13 at 23:47

0 Answers0