Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

r - Avoid overlapping columns with kable

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.

question from:https://stackoverflow.com/questions/65894520/avoid-overlapping-columns-with-kable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...