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

Vertical alignment in PDF file inside merged cells #639

Open
GauthierMagnin opened this issue Jun 14, 2024 · 0 comments
Open

Vertical alignment in PDF file inside merged cells #639

GauthierMagnin opened this issue Jun 14, 2024 · 0 comments

Comments

@GauthierMagnin
Copy link

Hello,

In PDF files, vertical alignment does not work for merged cells if any row contains multiple lines of text.
It looks like the position of the text is the result of shifting it from the bottom to the top of the cell and considering the height of the cell as if each row had the minimum height (like when using autofit) without considering their actual heights after defining the total width of the table.

Here is a reproducible example of an Rmd document:

---
title: "Vertical alignment in PDF file inside merged cells of a flextable"
date: "2024-06-14"
output:
  pdf_document:
    latex_engine: xelatex
---

```{r}
knitr::opts_chunk$set(echo = TRUE)

library(flextable)
library(magrittr)

set_flextable_defaults(theme_fun = "theme_vanilla")
```

Vertical alignment does not work in merged cells if any row contains multiple lines of text.

```{r}
lorem <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet aliquet nunc, ut euismod ex. Suspendisse pretium rhoncus nunc ac hendrerit. Donec sed felis sit amet lacus tristique dictum. Fusce viverra lorem iaculis turpis cursus viverra. Nam id velit in nisi tempor dignissim. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent eleifend lacus mi, ut aliquet quam consectetur quis. Donec euismod nulla et nulla vulputate pellentesque."

data_1 <- data.frame(col1 = c("A1", "A1", "A1"),
                     col2 = c("B1", lorem, "B3"))

flex_1 <- flextable(data_1) %>%
  
  width(1, unit = "cm", width = 2) %>%
  width(2, unit = "cm", width = 14) %>%
  
  merge_at(i = 1:3, j = 1)
```

\newpage

```{r}
valign(flex_1, valign = "top")
valign(flex_1, valign = "center")
valign(flex_1, valign = "bottom")
```


\newpage

No issues when each row has a height of a single line of text.

```{r}
data_2 <- data.frame(col1 = c("A1", "A1", "A1"),
                     col2 = c("B1", "B2", "B3"))

flex_2 <- flextable(data_2) %>%
  
  width(1, unit = "cm", width = 2) %>%
  width(2, unit = "cm", width = 14) %>%
  
  merge_at(i = 1:3, j = 1)
```

```{r results="hold"}
valign(flex_2, valign = "top")
valign(flex_2, valign = "center")
valign(flex_2, valign = "bottom")
```


\newpage

No issues when no cells are merged even if a row has a height of several lines of text.

```{r}
data_3 <- data.frame(col1 = c("A1", "A2", "A3"),
                     col2 = c("B1", lorem, "B3"))

flex_3 <- flextable(data_3) %>%
  
  width(1, unit = "cm", width = 2) %>%
  width(2, unit = "cm", width = 14)
```

```{r results="hold"}
valign(flex_3, valign = "top")
valign(flex_3, valign = "center")
valign(flex_3, valign = "bottom")
```

Here is the result of sessionInfo():

R version 4.0.5 (2021-03-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252   
[3] LC_MONETARY=French_France.1252 LC_NUMERIC=C                  
[5] LC_TIME=French_France.1252    

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

other attached packages:
[1] magrittr_2.0.1  flextable_0.9.6 knitr_1.46     

loaded via a namespace (and not attached):
 [1] zip_2.1.1               Rcpp_1.0.9              fontBitstreamVera_0.1.1
 [4] compiler_4.0.5          later_1.2.0             gfonts_0.2.0           
 [7] tools_4.0.5             uuid_1.0-3              digest_0.6.27          
[10] evaluate_0.23           jsonlite_1.7.2          lifecycle_1.0.4        
[13] rlang_1.1.3             shiny_1.6.0             cli_3.6.2              
[16] rstudioapi_0.13         yaml_2.2.1              crul_1.4.0             
[19] curl_4.3.1              fontLiberation_0.1.0    xfun_0.43              
[22] fastmap_1.1.1           xml2_1.3.2              officer_0.6.5          
[25] gdtools_0.3.7           systemfonts_1.0.3       askpass_1.1            
[28] grid_4.0.5              glue_1.4.2              httpcode_0.3.0         
[31] data.table_1.14.2       R6_2.5.0                textshaping_0.3.7      
[34] rmarkdown_2.22          fontquiver_0.2.1        promises_1.2.0.1       
[37] htmltools_0.5.8.1       ellipsis_0.3.2          mime_0.10              
[40] xtable_1.8-4            httpuv_1.6.1            rsvg_2.4.0             
[43] ragg_1.2.7              openssl_2.1.2           crayon_1.4.1     
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant