Kable () in knitting pdf looks oversized

I am using the kable () function to output a table in an Rmd knit pdf document. However, I am experiencing a problem. When I insert the pdf, the table it outputs is widened and clipped. See below layout code to run in Rmd knit pdf. As you can see the columns are missing:

```{r, echo=FALSE}
require(knitr)
col1 <- c("City", "Abidjan","Accra","Amman")
col2 <- c("Optimized HDH","217","281","26398")
col3 <- c("Standard HDH","0","0","37056")
col4 <- c("Heating Demand [W/(Β°C x Capita)]", "0.0","0.0","28.3")
col5 <- c("Heating Energy [kWh/(capita x yr)]","0","0","469.68")
col6 <- c("Threshold Temperature","23.3","24","17.6")
col7 <- c("Optimized CDH","31781","25264","32198")
col8 <- c("Standard CDH", "59398","58895","22059")
col9 <- c("Cooling Demand [W/(Β°C x capita)]", "1.67", "2.83", "45.72")
col10 <- c("Cooling Energy [kWh/(capita x yr)]", "53", "143.56", "1256.62")
tble <- data.frame(col1, col2, col3, col4, col5, col6, col7, col8, col9, col10)

colnames(tble) <- tble[1,]
tble <- tble[2:4,]
````

```{r, results='asis'}
# kable(tble)
```


|City    |Optimized HDH |Standard HDH |Heating Demand [W/(Β°C x Capita)] |Heating Energy [kWh/(capita x yr)] |Threshold Temperature |Optimized CDH |Standard CDH |Cooling Demand [W/(Β°C x capita)] |Cooling Energy [kWh/(capita x yr)] |
|:-------|:-------------|:------------|:--------------------------------|:----------------------------------|:---------------------|:-------------|:------------|:--------------------------------|:----------------------------------|
|Abidjan |217           |0            |0.0                              |0                                  |23.3                  |31781         |59398        |1.67                             |53                                 |
|Accra   |281           |0            |0.0                              |0                                  |24                    |25264         |58895        |2.83                             |143.56                             |
|Amman   |26398         |37056        |28.3                             |469.68                             |17.6                  |32198         |22059        |45.72                            |1256.62                            |

      

Do you know how to avoid this? Perhaps an input to kable () that asks to resize the table to 1 page? I'm tired of the search engine crawler and help, but didn't find any useful information.

Another question: is there a way to make the column names more than 2 rows instead of 1? My problem is that the collars are too long.

Very valuable!

+3


source to share


1 answer


There are many options for splitting text in cells or splitting a table if they are too wide pander

, for example:

> pander(tble, split.cells = 20, split.table = Inf)

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&nbsp;   City    Optimized HDH   Standard HDH    Heating Demand       Heating Energy       Threshold    Optimized CDH   Standard CDH    Cooling Demand       Cooling Energy    
                                                [W/(Β°C x Capita)]   [kWh/(capita x yr)]   Temperature                                  [W/(Β°C x capita)]   [kWh/(capita x yr)] 
------- ------- --------------- -------------- ------------------- --------------------- ------------- --------------- -------------- ------------------- ---------------------
 **2**  Abidjan       217             0                0.0                   0               23.3           31781          59398             1.67                  53          

 **3**   Accra        281             0                0.0                   0                24            25264          58895             2.83                143.56        

 **4**   Amman       26398          37056             28.3                469.68             17.6           32198          22059             45.72               1256.62       
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

      



Note that this is not supported style=rmarkdown

because pipe tables do not support line breaks. Use the pander

default style for multiple lines with pandoc

.

+4


source







All Articles