Include Tikz Code in Bookdown Figure Environment

TikZ libraries in bookdown

It turns out that you can simply put the \usetikzlibrary{...} command directly before the \begin{tikzpicture} and everything works fine :)

Using tikz in html_document using RMarkdown

I've just discovered that you can add tikz code in the code chunk of Rmarkdown when you modify the engine option :

---
output: html_document
---

Some picture

```{r,engine='tikz'}
\begin{tikzpicture}
\draw (0,0) circle (2cm);
\end{tikzpicture}
```

The problem is that the figure is pixelized and the scale is not respected. One way to solve this may be to change the extension of the figure output (to pdf) and the width and the height with the chunk options (e.g. equals to 3 inches) :

```{r,engine='tikz',fig.ext='pdf',fig.width=3}
\begin{tikzpicture}
\draw (0,0) circle (2cm);
\end{tikzpicture}
```

I'm sure there are better solutions but it's an easy way to use tikz code for an html output.

Cannot add tikz code snippet in my .Rmd post using blogdown

This turns out to be an issue in knitr which I just fixed on Github (I'm not sure if it is a bug of pdflatex). You may try

remotes::install_github('yihui/knitr')

Note that you will need to install two additional R packages, magick and pdftools, if they haven't been installed yet.



Related Topics



Leave a reply



Submit