从包含的tikz节点推断rmarkdown的小页面的大小 [英] Infering the size of a minipage from the containing tikz node for rmarkdown
问题描述
这是在rmarkdown的tikz节点标签中使用项目符号列表.我有一些TikZ
代码在纯LaTex
中可以正常工作,但在将其传输到出现错误! LaTeX Error: Something's wrong--perhaps a missing \item.
的rmarkdown
时却不能正常工作.这在答案中得到了解决在tmark的rmarkdown中的tikz的节点标签中,但是应用我在那里得到的解决方案时又出现了另一个问题.
This is a follow-up question to Using bullets list in tikz's node label in rmarkdown. I had some TikZ
code that works fine in pure LaTex
but NOT when I transport it to rmarkdown
where the error ! LaTeX Error: Something's wrong--perhaps a missing \item.
is raised. This was solved in the answer to Using bullets list in tikz's node label in rmarkdown but another issue arises applying the solution I got in there.
您可以参考原始问题(在rmarkdown的tikz节点标签中使用项目符号列表),但基本上我有一些TikZ
代码,可将图片用作更大的rmarkdown
文件的一部分.正如我在 https://www.overleaf.com/上进行的测试一样,它可以在LaTex
中工作在rmarkdown
中,它将引发缺少的项目错误.在在tikz节点中使用项目符号列表的拟议解决方案rmarkdown中的标签是要在rmarkdown
中添加一个\minipage
环境(请参见下面的代码).
You can refer to the original question (Using bullets list in tikz's node label in rmarkdown) but basically I have some TikZ
code for pictures to be used as part of a larger rmarkdown
file. It works in LaTex
as I tested in on https://www.overleaf.com/ but once in rmarkdown
, it raises the missing item error. The proposed solution in Using bullets list in tikz's node label in rmarkdown was to add a \minipage
environment in rmarkdown
(see the code below).
我在使用\minipage
环境时遇到的问题是,在创建应该是a的一部分的节点之前,我将不得不手动设置其宽度(或者至少我不知道如何自动执行此操作) TikZ
大图片.换句话说,我需要知道为每个节点分配的空间,以重现rmarkdown
中的图片.我想知道是否有一种方法可以预先推断节点的大小,以便我可以创建一个与其所包含的节点大小匹配的小页面.
My problem with the use of the \minipage
environment is that I will have to manually set its width (or at least I don't know how to automate this) before creating the node which is supposed to be part of a large TikZ
picture. In other words, I need to know the allocated space for each node to reproduce the picture in rmarkdown
. I was wondering whether there is a way to infer the size of the node in advance, so that I can create a minipage matching the size of the node it will contain.
\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}
我也愿意接受其他解决方案,只要我不必手动指定节点的大小即可.例如,做(注意注释行)
I am also open to other solutions as long as I will NOT have to specify the size of my nodes manually. For example doing (note the commented lines)
\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
中使用相同代码的东西,而不必手动指定节点上每个小页面的大小.
in TikZ
will infer the size of the node from its text size and I am looking for something that allows me to use the same code in rmarkdown
without having to manually specify the size of each minipage across my nodes.
推荐答案
您可以使用同名程序包中的varwidth
环境替换minipage
:
You could replace minipage
with the varwidth
environment from the package of the same name:
\documentclass{article}
\usepackage{tikz}
\usepackage{enumitem}
\usepackage{varwidth}
\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, font=\itshape, text=BulletsColor] (a) {
\begin{varwidth}{\textwidth}
p
\begin{myBullets}
\item \textcolor{BulletsColor}{first item}
\item \textcolor{BulletsColor}{second item}
\end{myBullets}
\end{varwidth}
}
;
\end{tikzpicture}
\end{document}
这篇关于从包含的tikz节点推断rmarkdown的小页面的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!