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

Multiple spaces are trimmed: Leading / trailing spaces are removed, mid-text spaces are converted into a single space #35

Open
yonbar opened this issue Feb 1, 2024 · 3 comments

Comments

@yonbar
Copy link

yonbar commented Feb 1, 2024

Multiple spaces are all trimmed: Leading / trailing spaces are removed, mid-text spaces are converted into a single space.
This includes markdown tricks, e.g.   or "\ua0" , with use_markdown either FALSE or TRUE.


library(gridtext)
library(grid)
library(reprex)

# January is led by regular spaces, March is led by non-breaking spaces by using ALT+0160
text <- c("   January", "Feb&nbsp;&nbsp;&nbsp;ruary", "    March", "\u00a0\u00a0\u00a0April", "____May", "Ju     ne", 
          "July                    ")

x <- (1:7)/9 + 1/30
y <- rep(0.8, 7)
g <- richtext_grob(
  text, x, y, halign = 0, hjust = 1,
  rot = 45,
  padding = unit(c(3, 6, 1, 3), "pt"),
  r = unit(4, "pt"),
  align_widths = TRUE,
  box_gp = gpar(col = "black", fill = "cornsilk", use_markdown = FALSE)
)
grid.newpage()
grid.draw(g)

Created on 2024-02-01 with reprex v2.0.2

@yonbar yonbar changed the title Multiple spaces are all automatically trimmed to a single space Multiple spaces are trimmed: Leading / trailing spaces are removed, mid-text spaces are converted into a single space Feb 1, 2024
@petermott
Copy link

I was intending to use the package to capture and present details of fit objects via cpature.output(summary(fit)). But these rely on spaces to format, and spaces as you not disappear.

@bwiernik
Copy link
Collaborator

Whitespace trimming is the expected behavior. You might try out the new marquee package to see if it meets your needs https://www.tidyverse.org/blog/2024/05/marquee-0-1-0/

@petermott
Copy link

petermott commented Nov 20, 2024

Whitespace trimming is the expected behavior. You might try out the new marquee package to see if it meets your needs https://www.tidyverse.org/blog/2024/05/marquee-0-1-0/

Alas it would not work on my setup - not at all. I opened an issue though since nothing happened Imcan't see that it will be much use. It was, in fact, Pedersen's patchwork package that set me looking for a way to write text into a grob to display next to a ggplot!

EDIT: The problem was I was using the Default R graphics engine. I switched to Cairo (in RStudio) and is worked. marquee does not force removal of whitespace and permits subscripts. So it will replace gridtext for me.

zmughal added a commit to zmughal-contrib/gridtext that referenced this issue Dec 2, 2024
Specifically, this allows for using non-breaking space ("\u00A0", "&nbsp;")
in text which is preserved when using SVG output.

Connects to:
- <wilkelab#35>,
- <wilkelab/ggtext#95>.
zmughal added a commit to zmughal-contrib/gridtext that referenced this issue Dec 2, 2024
Specifically, this allows for using non-breaking space ("\u00A0", "&nbsp;")
in text which is preserved when using SVG output.

Connects to:
- <wilkelab#35>,
- <wilkelab/ggtext#95>.
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

3 participants