从 rmarkdown 的包含 tikz 节点推断小页面的大小
Infering the size of a minipage from the containing tikz node for 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 的后续问题,但应用我在那里找到的解决方案会出现另一个问题。
可以参考原题() 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 是在rmarkdown
中添加了一个\minipage
环境(看下面的代码)
我在使用 \minipage
环境时遇到的问题是我必须在创建节点之前手动设置它的宽度(或者至少我不知道如何自动设置)成为大型 TikZ
图片的一部分。换句话说,我需要知道为每个节点分配的 space 才能重现 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}
in TikZ
将从节点的文本大小推断节点的大小,我正在寻找允许我在 rmarkdown
中使用相同代码而无需手动指定大小的东西我节点上的每个小页面。
您可以将 minipage
替换为同名包中的 varwidth
环境:
\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
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
可以参考原题(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 rmarkdown
中添加了一个\minipage
环境(看下面的代码)
我在使用 \minipage
环境时遇到的问题是我必须在创建节点之前手动设置它的宽度(或者至少我不知道如何自动设置)成为大型 TikZ
图片的一部分。换句话说,我需要知道为每个节点分配的 space 才能重现 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}
in TikZ
将从节点的文本大小推断节点的大小,我正在寻找允许我在 rmarkdown
中使用相同代码而无需手动指定大小的东西我节点上的每个小页面。
您可以将 minipage
替换为同名包中的 varwidth
环境:
\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}