Rmarkdown space without line break ~
Asked Answered
B

3

18

In Latex, it is possible to insert a space that does not end a line by a ~ character. So writing Fig.~\ref{fig:f1} will write as

Fig. 1

and it makes sure that text wrapping never breaks a line between Fig. and the number 1.

However, in Rmarkdown writing Fig.~\@ref(fig:f1), Fig.\~\@ref(fig:f1), or Fig.\\~\@ref(fig:f1 translates to Fig.\textasciitilde{}\ref{fig:f1} giving

Fig.~1

in the output. How do you insert the equivalent of ~ in rmarkdown? I am actually using bookdown.

Byline answered 6/6, 2016 at 19:40 Comment(0)
D
15

Insert a non breaking space manually using regular HTML:

...Fig. \@ref{fig:f1}...
Dormeuse answered 6/6, 2016 at 23:46 Comment(2)
Great! It even translates correctly to Latex and PDF (i.e., non HTML formats).Byline
Thanks so much! This even works if used in a r inline code chunk, e.g. within `r paste0(x, " ", y)`. Very handy! (I tried this in the docx output)Unripe
V
6

Use \ i.e. backslash then a space.

Fig.\ \@ref{fig:f1}

You could also use $~$, but this works only for PDF.

Fig.$~$\@ref{fig:f1}
Vacationist answered 20/2, 2020 at 9:35 Comment(0)
S
0

~ is just a shortcut for \nobreakspace{}. You can directly use the underlying macro to avoid rmarkdown interfering with the tilde:

test\nobreakspace{}test
Suellen answered 27/9, 2021 at 9:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.