You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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")
```
Verticalalignmentdoesnotworkinmergedcellsifanyrowcontainsmultiplelinesoftext.```{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")
```
\newpageNoissueswheneachrowhasaheightofasinglelineoftext.```{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)
```
```{rresults="hold"}
valign(flex_2, valign="top")
valign(flex_2, valign="center")
valign(flex_2, valign="bottom")
```
\newpageNoissueswhennocellsaremergedevenifarowhasaheightofseverallinesoftext.```{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)
```
```{rresults="hold"}
valign(flex_3, valign="top")
valign(flex_3, valign="center")
valign(flex_3, valign="bottom")
```
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:Here is the result of
sessionInfo()
:The text was updated successfully, but these errors were encountered: