Merck / r2rtf

Easily Create Production-Ready Rich Text Format (RTF) Table and Figure
https://merck.github.io/r2rtf
GNU General Public License v3.0
76 stars 19 forks source link

Set different border widths within a section #202

Closed pgseye closed 9 months ago

pgseye commented 9 months ago

I am wondering if it's possible to set different border widths in a section? For example, I am noticing that if I have a top and bottom border for a col_header, I don't necessarily want the bottom border to be the same thickness as the top border (see screenshot), I would like to make it thinner. Is this possible? example code:

  rtf_colheader(colheader = "Treatment Group | Visit | Timepoint | n | nBLQ | Mean | SD | CV% | Median | Minimum | Maximum | Geometric Mean | Geometric CV% ",
                col_rel_width = rel.width,
                text_justification = text.just,
                text_font = font,
                text_font_size = 7,
                text_format = "b",
                border_top = rep("", n.cols),
                border_right = rep("", n.cols),
                border_left = rep("", n.cols),
                border_width = 25) |> 
  rtf_body(as_colheader = F,
           col_rel_width = rel.width,
           text_justification = text.just,
           text_font = font,
           text_font_size = 7,
           border_first = rep("single", n.cols),
           border_last = rep("single", n.cols),
           border_left = rep("", n.cols),
           border_right = rep("", n.cols),
           border_width = 25,
           last_row = F) |> 
screenshot_1006

If I then add:

border_bottom = rep("single", n.cols),

to rtf_colheader and change the border width to 5, the top colheader border thins instead.

elong0527 commented 9 months ago

r2rtf define the border width as a scalar value that control all border width.

Would suggest to use different line type that can be controlled in each cell.

https://merck.github.io/r2rtf/articles/rtf-row.html#border-type

Alternatively, you can write a post-hoc function to modify the source code generated by "rtf_encode" to achieve the goal.

pgseye commented 9 months ago

Thank you but I can't see how to amend specific cells from that. I keep getting errors relating to incorrect number of dimensions when I try to specify cells. Say you have:

> matrix(r2rtf:::border_type()$name[1], nrow = 7, ncol = 3, byrow = TRUE)
     [,1] [,2] [,3]
[1,] ""   ""   ""  
[2,] ""   ""   ""  
[3,] ""   ""   ""  
[4,] ""   ""   ""  
[5,] ""   ""   ""  
[6,] ""   ""   ""  
[7,] ""   ""   ""  

How would I amend this to include a single border at the 4th row, leaving all other borders blank?

fb-elong commented 9 months ago

Simply define a matrix as argument input that has the same dimension of your input data.

library(r2rtf)
head(iris) %>%
  rtf_body(
    border_top = matrix(c("", "", "", "single", "", ""), ncol = 5, nrow = 6)
  ) %>%
  rtf_encode() %>%
  write_rtf("tmp.rtf")
pgseye commented 9 months ago

Thank you