【发布时间】:2019-06-17 14:08:36
【问题描述】:
这是Using bullets list in tikz's node label in rmarkdown 的后续问题。我有一些TikZ 代码可以在纯LaTex 中正常工作,但当我将其传输到rmarkdown 时会出现错误! LaTeX Error: Something's wrong--perhaps a missing \item.。这在Using bullets list in tikz's node label in rmarkdown 的答案中得到了解决,但是应用我在那里得到的解决方案会出现另一个问题。
您可以参考原始问题 (Using bullets list in tikz's node label in rmarkdown),但基本上我有一些 TikZ 代码用于将图片用作更大的 rmarkdown 文件的一部分。它在LaTex 中工作,因为我在https://www.overleaf.com/ 上进行了测试,但是一旦在rmarkdown 中,它会引发丢失项目错误。 Using bullets list in tikz's node label in rmarkdown 中建议的解决方案是在 rmarkdown 中添加一个 \minipage 环境(参见下面的代码)。
我在使用 \minipage 环境时遇到的问题是,在创建应该是大TikZ 图片。也就是说,我需要知道每个节点分配的空间来重现rmarkdown中的图片。我想知道是否有办法提前推断节点的大小,以便我可以创建一个与它将包含的节点大小相匹配的小型页面。
\documentclass{article}
\usepackage{tikz}
\usepackage{enumitem}
\begin{document}
\definecolor{BulletsColor}{rgb}{0, 0, 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}
}
\begin{tikzpicture}
\node[draw, rounded corners] (a) {
\begin{minipage}{2.5cm}
p
\begin{myBullets}
\item first item
\item second item
\end{myBullets}
\end{minipage}
}
;
\end{tikzpicture}
\end{document}
只要我不必手动指定节点的大小,我也愿意接受其他解决方案。例如做(注意注释行)
\begin{tikzpicture}
\node[draw, rounded corners] (a) {
% \begin{minipage}{2.5cm}
p
\begin{myBullets}
\item first item
\item second item
\end{myBullets}
% \end{minipage}
}
;
\end{tikzpicture}
在TikZ 中将根据其文本大小推断节点的大小,我正在寻找允许我在rmarkdown 中使用相同代码而无需手动指定节点中每个微型页面的大小的东西。
【问题讨论】:
-
可能与问题无关,但在 tikz 节点中使用 minipage 似乎有点矫枉过正。我建议简单地指定文本宽度,例如
\node[draw, rounded corners,text width = 3cm] (a){ p \begin{myBullets} \item first item \item second item \end{myBullets} }; -
"从包含 tikz 节点的 rmarkdown 推断 minipage 的大小" 如果您处于段落模式,则不能。段落在换行之前占用尽可能多的空间。所以一个段落,没有任何意义来计算它的大小是一个 TeX 错误。
-
如果你不想要 minipage,你可以使用
\node[draw,text width=3cm](a){P, etc}如果你不想要固定宽度,用1.2\widthof{my item width}替换它,它会随着你的字体缩放(使用 calc 包)。但是你需要引入一些宽度。最后一句话。如果所有节点都具有相同的大小(或者您有一组有限的不同大小),您的文档可能会看起来更好。因此,即使有可能,我认为让节点宽度完全适应实际文本也不是一个好主意。 -
@Liman 您是否尝试将
namely添加到节点选项中? -
@Liman 我还没有学会读心术:)
标签: r latex r-markdown knitr tikz