Next, a table will be created with a line break in the header:
```{r,echo=FALSE, results="asis"} library(pander) mytab = data.frame("ReallySuperExtraLongColumn\nNameThatIWantToWrap"=1:2, col2=2001:2002, check.names = FALSE) pandoc.table(mytab) ```
A line break is encoded with \n
. This is not a permitted character in the column name, and the data.frame()
function usually removes it. You can use check.names = FALSE
to suppress this behavior and save the column names exactly as you entered them. Alternatively, you can override the column name on a separate line:
mytab = data.frame(ReallySuperExtraLongColumnNameThatIWantToWrap=1:2, col2=2001:2002) names(mytab)[1] = "ReallySuperExtraLongColumn\nNameThatIWantToWrap"
You can also set the width of the cells using split.cells
. Then the line breaks will be generated automatically, however, the breaks appear only when there is a space in the column header. Example:
```{r,echo=FALSE, results="asis"} library(pander) mytab = data.frame("Really Super Extra Long Column Name That I Want To Wrap"=1:2, col2=2001:2002, check.names = FALSE) pandoc.table(mytab, split.cells = 15) ```
This gives breaks after Extra and Name. Note that you still need to check.names = FALSE
, because spaces are also not allowed in frame names.
Stibu source share