I am trying to produce a pdf using knitr, and the bottom figure of every page are cropped.
I used the following options:
output:
pdf_document:
fig_caption: no
fig_crop: false
latex_engine: xelatex
keep_tex: true
The last line keeps a separate copy of the figures, and they are complete!
I tried opening the document on several different computers (thinking it might be the pdf device driver), and the pdf document always comes out cropped.
I have the most recent version of Rstudio.
Any ideas?
Related
I am using the rmarkdown package to produce PDF slides with the Metropolis theme. Recently, I noticed that the equations started to appear differently - they use a different font.
Minimal example of *.Rmd file:
---
output:
beamer_presentation:
theme: "metropolis"
latex_engine: xelatex
keep_tex: true
---
## Problem with font
$$f(x_i\mid\mu,\sigma^2) = \exp\left\{-\frac{(x_i-\mu)^2}{2\sigma^2}\right\}$$
which, when knitted in RStudio, produces:
This looks different from what is obtained when compiling the same slide directly in LaTeX with xelatex:
\documentclass{beamer}
\usetheme{metropolis}
\begin{document}
\begin{frame}{Problem with font}
\[f(x_i\mid\mu,\sigma^2) = \exp\left\{-\frac{(x_i-\mu)^2}{2\sigma^2}\right\}\]
\end{frame}
\end{document}
which produces:
This does not look like a big difference, but in other equations some special characters are missing, and the font size is slightly different, affecting the whole layout of my slides.
After some investigation, it turns out that commenting out those two lines in the tex file produced by rmarkdown makes it better:
%\usepackage{unicode-math}
%\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
Is the unicode-math package the (only) culprit here? How to solve this problem and make sure that Metropolis uses the right fonts without manually changing the tex files?
Thanks in advance for your help!
System configuration:
RStudio 1.2.1335
rmarkdown 1.15
pandoc 2.3.1 (through RStudio)
Metropolis theme 1.2
Fira Sans font 4.3
XeTeX 3.14159265-2.6-0.999991 (TeX Live 2019)
What you are seeing is, indeed, the effect of the unicode-math package. There is a simple way to work around this by forcing pandoc to use the mathspec package instead. This can be done by setting mathspec: true in your metadata
---
mathspec: true
output: …
---
or by setting the respective variable when calling pandoc
---
output:
beamer_presentation:
theme: "metropolis"
latex_engine: xelatex
pandoc_args: ["--variable=mathspec"]
---
There is only a minor, very subtle, and mostly inconsequential difference between the two. I'd suggest to use the first version, as it is simpler.
See TeX StackExchange for a discussion of the differences between unicode-math and mathspec.
I used to be able to render images in r-markdown using a URL with the following code ![](https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark) but I get a file not found error ! LaTeX Error: File https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark' not found.
Am I missing packages? This code still works on some shiny apps published a few month ago.
Below the a working file r-markdown file:
---
title: "Test"
header-includes:
- \usepackage{graphicx}
output:
pdf_document:
latex_engine: xelatex
number_sections: yes
keep_tex: yes
classoption: article
papersize: A4
fontsize: 10pt
geometry: margin=0.9in
linestretch: 1.15
---
## R Markdown
![](https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark)
The LaTeX graphicx package does not include an http client, it is therefore not able to pull the image from the internet. However, a lot of the conversion work from Markdown to LaTeX is performed by pandoc, which can get this image. One just needs to tell pandoc to store all images locally by passing the --extract-media option. This allows LaTeX to find the images when it is invoked by RMarkdown.
---
output:
pdf_document:
pandoc_args: ["--extract-media", "."]
---
The above will store all images in the same directory as the Rmd file. The files will be named using SHA1 hashes, so you might want to use a separate directory for these files instead.
I'm using R-markdown for a couple of reports. I do it with self contained graphics because I send it via email.
This worked till recently. But now the images are not shown anymore (with the error of a cross in a box). It might be that I updated the Version of RStudio. I used this a the top of the script:
---
title: "blablablab"
author: "blablablab"
output:
html_document:
fig_caption: yes
toc: no
toc_depth: 2
toc_float: no
number_sections: false
self_contained: yes
---
I know that this question is not very specific. I just wanted to ask if there is anybody which also had self contained graphics which suddenly didn't work anymore.
Thanks for the help in advance!
Greetings Dani
I just had same problem. In RStudio i had previously:
output:
html_document:
self_contained: yes
and it always worked properly producing self-contained HTML. TODAY it stopped working properly. I did update Rstudio a few weeks ago and might not have noticed problem, not sure. SO now i changed to:
output:
html_document:
self_contained: yes
mode: selfcontained
Which seems strange and redundant with two separate lines trying to make things self-contained BUT it worked.
As a sanity check, make sure that you do not have the option include=FALSE in your global chunk options opts_chunk$set
When that is the case, the images are created and stored in the figure-html directory, but not embedded in the html file.
I have not been able to get an rmarkdown html notebook to pay attention to figure sizes that I specify. I've tried using knitr::opts_chunk$set(fig.width=7) and I've tried including the following:
output:
html_notebook:
fig_height: 5
fig_width: 7
toc: yes
toc_float:
collapsed: yes
What is the proper way to specify sizes and how does one vary the image size for different code chunks?
I'm confused about html notebook workflow in general, e.g., to run all the code then render it I've been using Run ... Run All then clicking on Preview. Is that the preferred method?
I'm using the latest version of the rmarkdown and knitr packages, R, and RStudio preview.
I am really digging into R-Markdown as a method of performing reproducible research. I have been successful in processing my Rmd files to both HTML and MS Word using knitr and pandoc (including passing both text and images through pander for fancifying). HTML is pretty straight forward, Word did a reasonable enough job (I had to do some additional formatting before submitting that manuscript).
Now, I'm trying to convert to PDF. I have customized the yaml header to look like this:
bibliography: citations.bib
output:
pdf_document:
fig_caption: yes
fig_crop: no
fig_height: 3
fig_width: 4.5
keep_tex: yes
latex_engine: xelatex
number_sections: yes
word_document:
fig_caption: yes
documentclass: article
csl: vancouver.csl
I am having one hell of a time with a very strange effect. Tables are set properly in the text, no problem. However, graphs (does not matter if it is ggplot2 or lattice) are hosing the typesetting up pretty badly. I've included a screencap to show you what is happening with the text. The image is up at the top of that page, and it's like the conversion to PDF considers the image as a line or two of text and does not account for the actual vertical space it is taking up. The page number is placed properly on the page as you will see, but text just keeps running all the way off and disappears into nothing. It's not on the next page, it's just gone.
Anyone seen something like this before? Is there something dumb I am doing?
Here's an example of a code block that creates an image with this phenomenon.
```{r echo=FALSE, fig.cap="This graph is going to be AWESOME."}
xyplot(x ~ y | z, myData, pch=19, type = c('p', 'r'), xlab="x-vals", ylab="y-vals", as.table=TRUE)
```
The above screencap that shows the problem. The line in the middle is the page divider in the R PDF viewer.