hughjonesd / huxtable

An R package to create styled tables in multiple output formats, with a friendly, modern interface.
http://hughjonesd.github.io/huxtable
Other
321 stars 28 forks source link

Outer borders not fully respected in HTML #113

Closed benedikt257 closed 4 years ago

benedikt257 commented 5 years ago

Hi, I think we might have hit on a bug in the package. Please find the bug report below - happy to help with any additional information! Cheers Benedikt

Describe the bug When selectively setting borders on a huxtable with merged cells, the pdf/LaTeX export places the borders in the wrong places.

Minimal Reproducible Example

library(huxtable)
library(tidyverse)
library(dplyr)

data(jams)
library(huxtable)
library(tidyverse)
library(dplyr)

data(jams)
jams_df <- data.frame(jams)
jams_df <- jams_df %>% add_row(Type = "", price = "", .before = 2)

ht <- jams_df %>%
  as_huxtable(add_colnames = FALSE) %>%
  set_all_border_colors("#003f94") %>%
  set_all_borders(0) %>%
  set_all_padding(value = 1) %>%
  merge_cells(1:2, 1:2) %>%
  set_left_border(1, 1, TRUE) %>%
  set_right_border(row = 1:2, col= 1,TRUE) %>%
  set_top_border(row = 1, col= 1:2, TRUE) %>%
  set_bottom_border(row = 1, col = 1:2, TRUE)

quick_pdf(ht, file="test.pdf")
quick_html(ht, file="test.html")

Expected behavior The above example generates an html and a pdf. The html output is as expected, with a border around the merged cell at the top of the table. The pdf output shows the misplaced borders.

System details

> packageVersion("huxtable")
[1] ‘4.6.0’
> R.Version()
$platform
[1] "x86_64-w64-mingw32"

$arch
[1] "x86_64"

$os
[1] "mingw32"

$system
[1] "x86_64, mingw32"

$status
[1] ""

$major
[1] "3"

$minor
[1] "6.1"

$year
[1] "2019"

$month
[1] "07"

$day
[1] "05"

$`svn rev`
[1] "76782"

$language
[1] "R"

$version.string
[1] "R version 3.6.1 (2019-07-05)"

$nickname
[1] "Action of the Toes"

RStudio: Version 1.2.1335 © 2009-2019 RStudio, Inc. Build 1379 (f1ac3452)

hughjonesd commented 5 years ago

Confirmed on my system. The HTML shows borders round the top merged cell. The PDF shows no right border around that cell, instead a border in the middle of the last two rows (to the right of "raspberry" and "plum").

hughjonesd commented 5 years ago

This also happens if you use the slightly more "correct":

jams_df %>%
    as_huxtable(add_colnames = FALSE) %>%
    set_all_border_colors("#003f94") %>%
    set_all_borders(0) %>%
    set_all_padding(value = 1) %>%
    merge_cells(1:2, 1:2) %>%
    set_all_borders(1, 1, 1) %>%
    quick_pdf(file = "test.pdf")
hughjonesd commented 5 years ago

Could you try github master and see if the fix works for you?

benedikt257 commented 5 years ago

Yes, excellent. That fixes the issue. Many thanks!

januz commented 4 years ago

... Thought I leave this here as it seems like a related problem, please tell me if you'd prefer if I opened a new issue...

I run into a (possibly) similar problem when using set_outer_borders(), e.g.,

jams_df %>%
  as_huxtable(add_colnames = FALSE) %>%
  set_all_border_colors("#003f94") %>%
  set_all_borders(0) %>%
  set_all_padding(value = 1) %>%
  merge_cells(1:2, 1:2) %>%
  set_outer_borders(2) %>%
  quick_pdf(file = "test.pdf")
hughjonesd commented 4 years ago

Is this with github latest?

januz commented 4 years ago

It was with the latest github version I installed yesterday. After installing the newest version today, the error is resolved for PDF output, but persists for HTML output.