Home > Enterprise >  Empty table grid on R markdown (html)
Empty table grid on R markdown (html)

Time:05-31

My R markdown report is going to be printed. I need to leave an empty 6 by 6 square grid for decisions to be later written on the printed report by hand.

This doesn't produce the desired result:

library(tidyverse)
library(kableExtra)

TableGrid <- matrix(NA,nrow =6, ncol=6)

options(knitr.kable.NA = '')

TableGrid %>%
  kbl(row.names = NA, col.names = NA, linesep = "") %>%
  kable_styling(full_width = F) %>%
  column_spec( 1, width = "3em", border_left = T, color = "black" ) %>%
  column_spec( 2, width = "3em", border_left = T, color = "black" ) %>%
  column_spec( 3, width = "3em", border_left = T, color = "black" ) %>%
  column_spec( 4, width = "3em", border_left = T, color = "black" ) %>%
  column_spec( 5, width = "3em", border_left = T, color = "black" ) %>%
  column_spec( 6, width = "3em", border_left = T, border_right = T, color = "black" ) %>%
  row_spec( 1, font_size=9, extra_css = "border-bottom: 1px solid; border-top: 1px solid" ) %>%
  row_spec( 2, font_size=9, extra_css = "border-bottom: 1px solid" ) %>%
  row_spec( 3, font_size=9, extra_css = "border-bottom: 1px solid" ) %>%
  row_spec( 4, font_size=9, extra_css = "border-bottom: 1px solid" ) %>%
  row_spec( 5, font_size=9, extra_css = "border-bottom: 1px solid" ) %>%
  row_spec( 6, font_size=9, extra_css = "border-bottom: 1px solid" ) 

Is there a way to create such an empty grid?
(bonus points: can this be written in a shorter way?)

edit:
My code indeed produces a 6x6 grid, but the font size doesn't control row height, and this it appears squashed and smallish on paper, i.e. not a square grid...

CodePudding user response:

With base R, you could draw a grid in a plot with fixed aspect ratio (asp=1):

```{r grid,fig.width=6,fig.asp=1}
par(mar=c(0,0,0,0))
plot(NA, asp=1, xlim=c(0,1),ylim=c(0,1),xaxt="n",yaxt="n",xlab="",ylab="", axes=T)
grid(6,6,lty="solid",col='black')
```

enter image description here

  • Related