Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save_as_image alignment issues #603

Closed
rosiebae opened this issue Jan 31, 2024 · 2 comments
Closed

save_as_image alignment issues #603

rosiebae opened this issue Jan 31, 2024 · 2 comments

Comments

@rosiebae
Copy link

rosiebae commented Jan 31, 2024

Hi, this is my first time posting so please let me know if I'm doing anything incorrectly.

I'm using the save_as_image function to save a table as a PNG file. I've been noticing that in some instances, an alignment issue occurs. Generally, it happens when I merge cells. There's no issue when I view the table in R Studio, but when I save it as an image, the issue pops up. Please see example screenshots below:

Screenshot of table from R Studio:
Capture

Saved PNG using save_as_image:
temp_tbl

Please find a minimal reproducible example below:

library(flextable)
library(tidyverse)

# Create mock data

text <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
source1 <- "DATA_SOURCE_A.COURSE_TITLE\nDATA_SOURCE_A.SUBJECT_DESCR\nDATA_SOURCE_A.CATALOG_NUMBER"
source2 <- "DATA_SOURCE_A.GRADING_BASIS\nDATA_SOURCE_A.OFFICIAL_GRADE\nDATA_SOURCE_B.STUDENT_GROUP"

temp_dat <- data.frame(
  label = c("Sources", "", "Notes"),
  col1 = c(source1, "", text),
  col2 = c(source2, "", text)
)

# Create table
temp_tbl <- flextable(temp_dat) %>%
  bg(bg = "#FFFFFF", part = "all") %>%
  merge_h(part = "body") %>%
  font(fontname = "Calibri", part = "all") %>%
  align(align = "left", part = "all")

save_as_image(temp_tbl, path = "temp_tbl.png", res = 300, expand = 0)

> sessionInfo()
R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/Chicago
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
 [1] lubridate_1.9.3 forcats_1.0.0   stringr_1.5.1   dplyr_1.1.4     purrr_1.0.2     readr_2.1.5     tidyr_1.3.1    
 [8] tibble_3.2.1    ggplot2_3.4.4   tidyverse_2.0.0 flextable_0.9.4
@davidgohel
Copy link
Owner

thanks for opening the issue (it's perfectly reproducible, don't worry)

We improved the rendering of text wrapping (note support for \t is also improved) but there are still misalignment, especially when the text is right aligned. You can test with the dev version

Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants