I have a tikz code to generate some graphs that works properly in latex
(tested on overleaf: https://www.overleaf.com). However, this is supposed to be part of a large rmarkdown
file but I cannot seem to use bullets list in some of my node labels while in rmarkdown
. My questions are:
- how can I use a list of bullets as tikz's node label in
rmarkdown
? - how can I customize that list to include some formatting like color, margin etc.?
- Where do things defined in
latex
using\newlist
,\setlist
go when usingrmarkdown
?
I could generate these figures in latex
and include them using knitr::include_graphics(...) but I prefer to use a more automatic way where I could just let the code generates the figures and embeds them as they arise into the file.
---
title: "Title"
author: "Me"
output:
bookdown::pdf_document2:
keep_tex: yes
latex_engine: xelatex
---
The following works fine outside a knitr chunk.
p
\begin{itemize}
\item first item
\item second item
\end{itemize}
It will also work inside the knitr chunk as node label when that label does not involve the item list. Otherwise, it results in: ! LaTeX Error: Something's wrong--perhaps a missing \item.
```{tikz, tikz-ex, echo=F, fig.cap = "Funky tikz", fig.ext = 'png', cache=TRUE, eval=T, engine.opts = list(template = "tikz2pdf.tex")}
\usetikzlibrary{arrows, shapes}
\definecolor{myColor}{rgb}{0.98, 0.94, 0.9}
\begin{tikzpicture}
\tikzstyle {stile} = [
ellipse,
draw=myColor,
fill=myColor,
thick,
inner sep=0pt,
text centered,
align=center
]
\node [stile](P){
p
\begin{itemize}
\item first item
\item second item
\end{itemize}
};
\end{tikzpicture}
The tikz2pdf.tex contain is the following:
\documentclass{article}
\include{preview}
\usepackage[utf8]{inputenc}
\usepackage[skins]{tcolorbox}
\usepackage{
tikz,
enumitem,
xcolor
}
\usetikzlibrary{
shapes,
arrows
}
\begin{document}
\begin{preview}
\end{preview}
\end{document}
Ultimately, I would like to customize this list to change the formatting of the items such as colors, margins etc. For this, I have the following code that also works in latex
but I am not sure where to put it when using rmarkdown
.
\definecolor{BulletsColor}{rgb}{0.98, 0.94, 0.9}
\newlist{myBullets}{itemize}{1}
\setlist[myBullets]{
label=\textcolor{BulletsColor}{\textbullet},
leftmargin=*,
topsep=0ex,
partopsep=0ex,
parsep=0ex,
itemsep=0ex,
before={\color{BulletsColor}\itshape}
}
Ideally, I would like to be able to use this just as I would do in latex
as:
\node [stile](P){
p
\begin{myBullets}
\item first item
\item second item
\end{myBullets}
};
I expect(and sorry I could not provide a complete picture) the output to be something like :
P
- first item
- second item
in the node label.