I’m struggling with a specific issue with the flextable-package.
I want to export tables in .svg format, using a custom (company) font. However, when I combine this custom font with the autofit()
function, some values get extra whitespaces after exporting. In the viewer I don’t these extra whitespaces.
If I don’t use the autofit()
function some values will get split over two rows and that also doesn’t work.
Also if I don’t specify the custom font, it works fine. But again, I need to use a specific font.
I can’t share the specific font here, but the issue seems to occurs with different fonts as long as they’re not already preloaded. So for example I’ve been able to replicate the issue with Monday Sans. It looks like this:
It’s less noticeable here, but with the company font I’m using you definitely see it.
I’m also open to other solutions, but I prefer something within flextable as it seems to offer a lot of options for different types of tables. I’ve already tried trimming and converting the values into factors, but no results.
Data:
structure(list(land_concat = c("Verenigd Koninkrijk", "Kenia",
"Italië", "Australië", "Griekenland"), diff = c("+10", "+9",
"+8", "+8", "+8")), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame"))
And script:
library(showtext)
library(flextable)
library(tidyverse)
# Adding the custom font
font_add(
"Monday",
regular = "C:\Users\***MYUSERNAME***\Documents\R\RFonts\MondaySans.ttf"
)
# Set font and colour
set_flextable_defaults(
font.family = "Monday",
font.color = "#535353",
decimal.mark = ",",
big.mark = "."#,
# line_spacing = 1.3,
)
# Convert, fit and export
flextable(DF) %>%
autofit() %>% save_as_image( path = "DF.svg")