Breaking lines in colnames or rownames

3

This is an example of a report I'm making. Because the margin settings are already set, when you change the column names with the columns, it ends up passing the margin. Any help how to break this line? For example from the "ARIMA Forecast". Here's a picture of how you could stay.

x<-runif(n=15,min=1,10)y<-runif(n=15,min=1,10)z<-runif(n=15,min=1,10)w<-runif(n=15,min=1,10)k<-runif(n=15,min=1,10)df_exemplo<-data.frame(x,y,z,w,k)colnames(df_exemplo)<-c("Previsto ARIMA", "Previsto Holtwinters", "Observado", "Erro ARIMA (%)", "Erro Holtwinters (%)")
    
asked by anonymous 11.07.2018 / 14:53

1 answer

3

I recommend using the kableExtra package to format tables in knitr or sweave . It works in conjunction with the kable function of the knitr package and the results are very cool. See below:

Hereisthecodeusedtocreatethistable:

\documentclass{article}\usepackage{booktabs}\usepackage{makecell}\begin{document}<<Dados>>=x<-runif(n=15,min=1,10)y<-runif(n=15,min=1,10)z<-runif(n=15,min=1,10)w<-runif(n=15,min=1,10)k<-runif(n=15,min=1,10)df_exemplo<-data.frame(x,y,z,w,k)colnames(df_exemplo)<-c("Previsto ARIMA", "Previsto Holtwinters", 
                          "Observado", "Erro ARIMA (%)", 
                          "Erro Holtwinters (%)")
@


<<TabelaComQuebra, warning=FALSE>>=
library(knitr)
library(kableExtra)

kable(df_exemplo, "latex", booktabs=TRUE, digits=4) %>%
  column_spec(1:5, width = c("1.5cm", "2cm", "2cm", "2cm", "2.5cm"))
@


\end{document}

Note that I had to load two LaTeX packages in order for the table to exit in this format. The line break in the table title quit automatically when using the column_spec function. I just set the width I would like the column to have and the software did the rest.

    
12.07.2018 / 01:45