0

I am looking to produce a tikz figure with a node triangle. Most ressources I have found online use \usetikzlibrary{shapes} and its regular polygon. Rmarkdown seems unable to use it.

This will work in overleaf :

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}
\begin{figure}
    \centering
\begin{tikzpicture}
\node [draw, circle,minimum size=1cm,thick] (cir) at (0,0) {Test};
\node [draw,regular polygon, regular polygon sides=3, inner sep=0pt, minimum size=1cm,thick] (tri) at (0, -2) {Test};
\end{tikzpicture}
\end{figure} 
\end{document}

but not in Rmarkdown.

---
title: "Untitled"
author: "My name"
output: pdf_document
header-includes: 
  - \usepackage{tikz}
  - \usetikzlibrary{shapes}
---

```{tikz}
\begin{tikzpicture}
\node [draw, circle,minimum size=1cm,thick] (cir) at (0,0) {Test};
\node [draw,regular polygon, regular polygon sides=3, inner sep=0pt, minimum size=1cm,thick] (tri) at (0, -2) {Test};
\end{tikzpicture}
```

I received this error.

processing file: tests.Rmd

! Package pgfkeys Error: I do not know the key '/tikz/regular polygon' and I am
 going to ignore it. Perhaps you misspelled it.

Quitting from lines 11-15 (tests.Rmd) 
Erreur : LaTeX failed to compile tikz2b045722257b.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See tikz2b045722257b.log for more info.
4
  • Welcome to TeX.SE!
    – Mensch
    Oct 29, 2021 at 19:44
  • Long time lurker, first time poster! @Mensch
    – POC
    Oct 29, 2021 at 19:45
  • Have you tried shapes.geometric instead of shapes?
    – Wulle
    Oct 29, 2021 at 19:49
  • Yes, but it did not worked. I have found out that you can call \usetikzlibrary{shapes} in the figure.
    – POC
    Oct 29, 2021 at 19:53

1 Answer 1

0

By looking at this post, I have tried to write \usetikzlibrary{shapes} in the \begin{tikzpicture} to \end{tikzpicture} and it worked!

Here is the solution:

title: "Untitled"
author: "My name"
output: pdf_document


{tikz}
\begin{tikzpicture}
\usetikzlibrary{shapes}
\node [draw, circle,minimum size=1cm,thick] (cir) at (0,0) {Test};
\node [draw,regular polygon, regular polygon sides=3, inner sep=0pt, minimum size=1cm,thick] (tri) at (0, -2) {Test};
\end{tikzpicture}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .