4

I'm developing an R Markdown script (whose output must be pdf_document) to generate a report with graphs and tables of a database data (I get this data through API calls) and I don't know how to avoid column overlapping when I get long texts.

screenshot of table

kable(dataframe, row.names = FALSE, longtable = TRUE, align = c('l', 'c', 'c', 'c'), booktabs = T) %>%
 kable_styling(position = "left",
               latex_options = "repeat_header",
               font_size = 9) %>%
 row_spec(0, bold = T, color = "white", background = "#00B2A9") %>%
 column_spec(1, width = "3.5cm") %>%
 column_spec(2, width = "5cm") %>%
 column_spec(3, width = "3cm") %>%
 column_spec(4, width = "7cm")

 dataframe
 #        Status
 # 1     DELETED
 # 2     DELETED
 # 3 NOT SAMPLED
 # 4     PLANNED
 # 5     PLANNED
 #                                                                     Point
 # 1                                                                  Point1
 # 2 Suuuuuuuuuuuuuuuuuupeeeeeeeeeeeeeer loooooooooooooong poooooooooooooint
 # 3                                                                  Point5
 # 4                                                                  Point1
 # 5                                                                  Point5
 #          Plan Date           Reason
 # 1 2020/02/05 07:55                -
 # 2 2020/12/10 22:00 That's my reason
 # 3 2020/12/11 10:30   Another reason
 # 4 2020/12/03 16:30                -
 # 5 2020/09/14 16:00                - 

For this table, I could increase the width of the second column_spec, but I have the same column in many tables and some of them have 9-10 columns, so it's not a good solution because the width of the table would exceed the right margin of the document.

Thanks for the help in advance and sorry if this question or similar has already been resolved.

  • 1
    Hi Michael, posting a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) will help us help you. Can you include `dput(head(dataframe))` or something similar to help us see what's causing you issues? – Dubukay Jan 26 '21 at 01:46
  • @Dubukay Do you have any idea how I can fix it? :( – Michael Scarn Jan 27 '21 at 17:52

0 Answers0