0

I'm using the default setting of bookdown (r Markdown) and I would like to create simple and complex tables by hand. I can create simple tables, such as this one:

simple table

However, when I try to add "two" headers, merge cells, and merge columns, the output is pretty ugly.

second table

I've tried to implement this response here, but I had no success at all.

Important notes: I'm using the standard setting of bookdown/r markdown. I don't know how to install packages or modules, but I can do that if needed. ; the codes I'm using are below:

| This row needs to fit the table
| Software | Price | Advantages
| :----------- | :----------- | :-----------
| R | Free | Open source
| SPSS | I don't know | Advantage 1

Software Price Advantages
R Free Open source
SPSS I don't know Advantege 1
Luis
  • 1,388
  • 10
  • 30

1 Answers1

0

You could use the package kableExtra, if you are looking for a .pdf version. You can find more information here: http://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf. For a HTML version, check this: https://haozhu233.github.io/kableExtra/awesome_table_in_html.html#Grouped_Columns__Rows.

Example of .Rmd file:

---
title: "Untitled"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r pdf_example}
library(kableExtra)

df <- data.frame("Software" = c("R", "SPSS"), 
                 "Price" = c("Free", "I don't know"), 
                 "Advantages" = c("Open source", "Advantage 1")) 

kbl(df, booktabs = T) %>%
  kable_classic() %>%
  add_header_above(c("This row needs to fit the table" = 3))

```

This code produces:

enter image description here

bttomio
  • 2,206
  • 1
  • 6
  • 17
  • Thank you. Sometimes, I use kableextra to report certain outputs. However, I would like to "draw" tables directly on R Markdown instead of creating data frames and using kableextra to report them. :) – Luis Jan 27 '21 at 21:02
  • It's all good, you're welcome. I did not see in your question that you were not looking for a kableextra answer. Does this help you: https://stackoverflow.com/a/61053409/13249862? – bttomio Jan 27 '21 at 22:24
  • 1
    Thank you. Part of my question was solved with your link! =) – Luis Jan 27 '21 at 23:55