我有一个tikz代码用于生成一些图形,在latex
中可以正常工作(已在overleaf测试:https://www.overleaf.com)。然而,这应该是一个大型的rmarkdown
文件的一部分,但我似乎无法在rmarkdown
中使用节点标签的项目符号列表。我的问题如下:
- 如何在
rmarkdown
中使用带有项目符号列表的tikz的节点标签? - 如何自定义该列表以包括一些格式设置,如颜色、边距等?
- 使用
rmarkdown
时,使用\newlist
、\setlist
在latex
中定义的内容会放到哪里?
我可以在latex
中生成这些图像,并使用knitr::include_graphics(...)将它们包含进来,但我更喜欢使用一种更自动化的方式,让代码生成图像并在出现时将其嵌入到文件中。
---
title: "Title"
author: "Me"
output:
bookdown::pdf_document2:
keep_tex: yes
latex_engine: xelatex
---
以下内容在 knitr 代码块外部运行正常。
p
\begin{itemize}
\item first item
\item second item
\end{itemize}
当节点标签不涉及项目列表时,它也可以作为knitr代码块内的节点标签。否则,它会导致以下错误:! 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}
tikz2pdf.tex文件的内容如下:
\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}
最终,我想自定义此列表以更改项目的格式,例如颜色、边距等。为此,我有以下代码,在latex
中也可以使用,但我不确定在使用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}
}
理想情况下,我希望能像在LaTeX中一样使用它:
latex
。 \node [stile](P){
p
\begin{myBullets}
\item first item
\item second item
\end{myBullets}
};
我希望(抱歉我无法提供完整的图片),输出结果应该类似于:
P
- 第一项
- 第二项
在节点标签中。