Merck / r2rtf

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

Indentation for footnote #141

Closed Rednose22 closed 1 year ago

Rednose22 commented 1 year ago

Hi there, recently we tried to add indentation for footnote in the rtf_footnote function with the combination of text_indent_left argument and text_indent_first argument. But it didn't work. Since it's included in one cell.

  col_indent_first <- c(-250, rep(0, 6))
  style_indent_footer <- matrix(c(250, rep(0, 6)),  byrow = T, nrow = length(end_notes), ncol = 7)

 r2rtf::rtf_footnote(
      footnote = end_notes,
      text_indent_left = style_indent_footer,
      text_indent_first = col_indent_first,
      as_table = TRUE
    )

Then the indentation would be like screenshot below. image

After looking into the codes, I guess it's caused by as_rtf_footnote function. In the encode process, the footnote section is treated as one cell so that the indentation only work on one footnote.

text_matrix <- matrix(paste(text_matrix, collapse = "\\line "), nrow = 1, ncol = 1)

attr(text, "text_convert") <- matrix(FALSE, nrow = 1, ncol = 1)

So one solution but not perfect is converting the endnote as a matrix and

foot.matrix <- matrix(c(end_notes, rep(rep('', length(end_notes),), 6)), byrow = F, nrow = length(end_notes), ncol = 7)
footer_style_indent_left <- matrix(c(250, rep(0, 6)),  byrow = T, nrow = length(end_notes), ncol = 7)

 r2rtf::rtf_footnote(
      footnote = foot.matrix,
      text_indent_left = footer_style_indent_left,
      text_indent_first = col_indent_first,
      as_table = FALSE
    )

Then the indentation could be as below: image

The imperfect point is obviously since footnote is not a part of table and no border around. So I'm wondering if as_rtf_footnote function could be updated.

fb-elong commented 1 year ago

The bug should be fixed in #142. Thanks!