r - 从 rmarkdown 的包含 tikz 节点推断 minipage 的大小
问题描述
这是在 rmarkdown 的 tikz 节点标签中使用项目符号列表的后续问题。我有一些TikZ
代码在纯代码中可以正常工作,LaTex
但当我将其传输到引发rmarkdown
错误的地方时却不行。! LaTeX Error: Something's wrong--perhaps a missing \item.
这在 rmarkdown 中使用 tikz 的节点标签中的项目符号列表的答案中得到了解决,但是应用我在那里得到的解决方案会出现另一个问题。
您可以参考原始问题(Using bullets list in tikz's node label in rmarkdown),但基本上我有一些TikZ
图片代码可用作较大rmarkdown
文件的一部分。LaTex
正如我在https://www.overleaf.com/上测试的那样,它可以正常工作,但是一旦进入rmarkdown
,它就会引发丢失项目错误。在 rmarkdown 中使用 tikz 的节点标签中的项目符号列表中提出的解决方案是在其中添加一个\minipage
环境rmarkdown
(参见下面的代码)。
我使用环境的问题是,在创建应该是大图片\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}
inTikZ
将根据其文本大小推断节点的大小,我正在寻找允许我使用相同代码的东西,rmarkdown
而无需手动指定节点上每个 minipage 的大小。
解决方案
您可以用同名包中的环境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}
推荐阅读
- java - 如何根据标题从RecyclerView打开一个项目到另一个项目 - MYSQL数据库
- python - 分组时获取两列字典列表
- python - 如何获得任意数的除数
- mysql - 如何有效地将动态文本保存到数据库中?
- rust - 返回实现多个特征的对象 - 装饰器模式
- angular - 将数据从组件传递到 Angular 2 中的模块
- sql - 如何在 CLOB 字段的第 10 位进行 regex_replace
- python - Getting URL as a parameter in Flask - but Flask stripping out the params from the URL
- css - 卡片使用 MaterializeCSS 和 VUE 跳过行
- java - IntelliJ IDEA 在调试时卡在“收集数据”