Less space between letters and units in rmarkdown (pdf and docx output) - r

I cannot find any information about spacing between letters in R Markdown. All I found only were questions about vertical spacing. I basically have two issues:
In LaTeX I usually use the siunitx package to correctly typeset numbers and units. I can of course use this in R Markdown as well if I load the package with \usepackage{siunitx}. But this does not output to the docx format, only to pdf. That brings me to my other question...
So I tried using different spaces of LaTeX to display numbers and their units with at least less space, e.g. writing 40\,m^2 to display 40 m² (in LaTeX I would use \SI{40}{\square\meter}). However, apparently R Markdown does not handle the \, nor \; at all, not even in the pdf output.
Question: What is the correct way to add smaller spaces between letters in R Markdown? (irrespective of output format!) How do I replace the \, command?
And: Is there a way to handle units nicely using R Markdown? I have found this question on the R units package, and I could live with it. That is, if I want to write hardcoded numbers like 40 m² I would have to use something like`r format(set_units(40, m2))`,right?.

Have you tried adding thin spaces using Unicode chars? For example, this page http://jkorpela.fi/chars/spaces.html suggests that "\u2009" and "\u200A" should display as thin spaces.
When I try this with a PDF document (using latex_engine: xelatex to handle Unicode), this is what I see:
It also appears to work with HTML and Word output.
Edited to add:
To be clear, this needs to go through R. If you want it inline, use code like this:
This is standard spacing: 40 m²,
this is narrow `r knitr::asis_output("40\u2009m²")` spacing.
This produces this output in PDF:

Related

Flextable export and image width issues

I am producing some tables which I now wish to incorporate into a latex document (not knitted by R but externally built).
I gather that flextable can now produce latex, but is this ONLY for knitting or can I export it somehow?
Failing that I'm guessing that exporting as an image might be the next best thing?
The tables though are quite wide and I intend to use them in the document rotated (landscape). How do I specify the width of the final image I need, and the DPI I'd like?
Finally, whilst testing all this in an Rmd script, my table columns are getting wrapped as I increase the number of columns. Is there some way to increase the maximum width available to print?
Updates:
Adding to the .rmd script
{r plotting fig.width=12, fig.height=8, dev='png'}
does NOT fix the visible porthole size.
It would appear that when flextable thinks it's running out of room it starts breaking the column contents at spaces, overriding the width() specification. Replacing the spaces with non-breaking spaces seems to restore some order here.

markdown insert tabulator (R)

Is there a way to insert tabulators in R markdown code?
I just want to show sth. like
attendees: 33
sick leave: 1
presenters: 5
Text is Markdown text, numbers are inline R code. Simply putting spaces does not work, since there is a variably spaced font.
Ideally working for both HTML and PDF output. (I work on Win-10 in RStudio)
All my searches ended up in (a) creating markdown tables (too big), or (b) how to create tabs for tabbed browsing, much more complicated. I tried \t and \t, does not work.
I use either the RStudio add-in BeautifyR which has a nice Beautify Table. Got the top banner under Tools there is the Add-ins button load BeautifyR.
Then there is also using Kable. Look for the R packages and install: knitr::kable and kableExtra.

rmarkdown: new behaviour when knitting pdf documents

I tried to knit an old rmarkdown document to pdf recently. In the document, I had used the tilde symbol to denote a non-breaking space, e.g. 'Figure~2'. This syntax now seems to behave differently, now it prints 'Figure~2' verbatim, with the tilde printed in the document. There are many other differences, for instance % would once be interpreted as a comment, now it is printed.
I'm using Debian stretch with RStudio-1.2.1335. I can't find any documentation of this change in rmarkdown, pandoc or RStudio. Does anyone know what caused this change? Or how to revert to the old behaviour? Thanks.
The pandoc solution is to simply escape a space:
This is a short\ sentence.
Then a tilde will appear in the tex output.
What might work as well is $nbsp;:
This is a short sentence.
And if you really like your TeX then use \protect{~}:
This is a short\protect{~}sentence.

How can I write a degree symbol in RMarkdown 2?

I'm writing some code with descriptions using Rmarkdown 2 and knit PDF.
I've been trying many method to write a degree symbol inline:
Latex package: siunitx's \ang
Latex package: textcomp's \textdegree
Latex: \circ
And many possible RMarkdown symbols, such as:
$$ \textdegree $$ or $\textdegree$
But nothing is working. Is there a way to write a degree symbol in RMarkdown 2 and convert it do PDF?
EDIT (18 AUGUST 2014):
Ok, I found out where is the problem. If you use \circ in normal sentence or first-level list it is ok. But when I try to use \circ in second-level list - it's not working.
The problem was with RMarkdown converting nested lists. On this page http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html you can find sentence:
The nested list must be indented four spaces or one tab
Although, using the tab could be a problem. When using four spaces - it works:
* Let's turn this round 360$^\circ$
+ Let's turn this round 360$^\circ$
Using \circ works for me, RStudio, knit to pdf:
Let's turn this round 360$^\circ$
You can use plotmath's degree, e.g.
plot(1, xlab=expression(4*degree))

have knitr output figures in different formats

Let's say I have a long report that produces a lot of figures which knitr makes as pdfs and it works really well with LaTeX. At the end of the project, my co-authors would like to have also raster based figures. One option would be to convert everything using ImageMagick. Another option would be to specify for each chunk dev = c("jpg", "pdf"), but given the number of figures, this could be cumbersome.
Is there a global switch to make knitr produce figures in pdf and other formats at the same time?
I think in the preamble
opts_chunk$set(dev = c("pdf", "jpg"))
should do. Within a R-chunk of course.

Resources