让我们考虑一下我在
Tikz:边缘右侧的节点与其他节点与 tcbtheorem 交互
这是一个使用 TikZ 在边注周围绘制彩色框的命令。
由于此注释是由 TikZ 绘制的,因此它不被识别为边缘内容,并且可以与旁注重叠。
例如:
\documentclass[oneside]{book}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikzpagenodes}
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{lipsum}
\usepackage{marginfix}
\usepackage{sidenotes}
\newcounter{mycaution}
\newcommand\tikzmark[1]{%
\tikz[remember picture,overlay]
\node[inner xsep=0pt,outer sep=0pt] (#1) {};
}
\newcommand{\caution}{
\stepcounter{mycaution}
\tikzmark{\themycaution}%
\begin{tikzpicture}[remember picture,overlay]
\node[draw=red,anchor=west,xshift=\marginparsep,yshift=0pt]
(mybox\themycaution)
at ([yshift=3pt]current page text area.east|-\themycaution)
{\parbox{\marginparwidth}{Some text, even a longer text}};
\end{tikzpicture}
}
\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum
ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero,
nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla
ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in,
pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean
faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor
semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend,
sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem
non justo. Nam\sidenote{Random sidenote with a bit long text.} lacus libero, pretium at, lobortis vitae, ultricies et, tellus. Donec aliquet,
tortor sed accumsan bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi.\caution{}
Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa. Cras nec ante. Pellentesque a
nulla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus
mus. Aliquam tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque cursus
luctus mauris.
\end{document}
产量:
为了避免这种行为,我想caution
在边距中“阻止”框的高度,这样其他东西就无法进入那里。包包marginfix
提供了\marginphantom
似乎符合我要求的命令。但是,\marginphantom{2cm}
在caution
定义之前tikzpicture
(或\tikzmark
定义内部)添加定义不起作用。
您是否想到了另一种解决方案,可以在边距中阻挡caution
框所需的空间,以便它不会与其他边距材料重叠(我正在考虑\marginpar
或\sidenote
)。 (此外,如果有人能解释我提议的用法有什么问题,我将不胜感激\marginphantom
)。
编辑
澄清一下:在这里定义和使用命令\tikzmark
是因为我希望框位于被caution
调用的准确位置。
此外,我需要的框比红色框更复杂,所以我需要 TikZ 来绘制它,我不能使用类似的东西colorbox
。
答案1
避免重叠的最简单方法是将tikzpicture
自身包装到as\sidenote
的定义中\caution
\sidenote{%
\tikzpicture[remember picture]
\node[draw=red,anchor=west,xshift=\marginparsep,yshift=0pt]
(mybox\themycaution)
at ([yshift=3pt]current page text area.east|-\themycaution)
{\parbox{\marginparwidth}{Some text, even a longer text}};
\endtikzpicture
}
请注意,在这种情况下必须取消“覆盖”选项。
现在,您必须禁用这些旁注的编号并抑制计数器的增量sidenote
:
\newcommand{\caution}{%
...
\begingroup
\let\thesidenote\relax
\let\refstepcounter\@gobble
\sidenote{%
...
}
\endgroup
}
完整代码
\documentclass[oneside]{book}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikzpagenodes}
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{lipsum}
\usepackage{sidenotes}
\usepackage{marginfix}
\newcounter{mycaution}
\newcommand\tikzmark[1]{%
\tikz[remember picture,overlay]
\node[inner xsep=0pt,outer sep=0pt] (#1) {};
}
\makeatletter
\newcommand{\caution}{%
\stepcounter{mycaution}%
\tikzmark{\themycaution}%
\begingroup
\let\thesidenote\relax
\let\refstepcounter\@gobble
\sidenote{%
\tikzpicture[remember picture]
\node[draw=red,anchor=west,xshift=\marginparsep,yshift=0pt]
(mybox\themycaution)
at ([yshift=3pt]current page text area.east|-\themycaution)
{\parbox{\marginparwidth}{Some text, even a longer text}};
\endtikzpicture
}%
\endgroup
}
\makeatother
\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum
ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero,
nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla
ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in,
pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean
faucibus.\caution Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor
semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend,
sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem
non justo. Nam\sidenote{Random sidenote with a bit long long long long long long long long long long long long text.} lacus libero, pretium at, lobortis vitae, ultricies et, tellus. Donec aliquet,
tortor sed accumsan bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi.\caution
Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa. Cras nec ante. Pellentesque a
nulla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus
mus. Aliquam tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque cursus
luctus mauris.
\end{document}