我需要进行一些计算,其中tcolorbox
必须引入 a 的实际高度(请参阅以下代码以了解我的目的)。我想知道是否有这样的宏(我的代码中的 \macro 作为示例,而不是\tcbtextheight
)来存储实际框高度的值。
\documentclass[12pt,a4paper]{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tcolorbox}[
lefthand width=3em,
arc=3mm,
boxrule=0pt,sidebyside,enhanced,
colback=green!60,
bicolor,colbacklower=gray,
collower=white,
underlay={
\path[fill=green!60]
(segmentation.south) -- ++(0.5\macro,0.5\macro)--(segmentation.north);},
]
Upper
\tcblower
\quad This is the lower part.
\end{tcolorbox}
\end{document}
答案1
在这个例子中,最干净的方式是从 中提取高度尺寸segmentation
。因此,
\tcbsetmacrotoheightofnode\macro{segmentation}
就可以了。
完整代码如下:
\documentclass[12pt,a4paper]{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tcolorbox}[
lefthand width=3em,
arc=3mm,
boxrule=0pt,sidebyside,enhanced,
colback=green!60,
bicolor,colbacklower=gray,
collower=white,
underlay={
\tcbsetmacrotoheightofnode\macro{segmentation}
\path[fill=green!60]
(segmentation.south) -- ++(\dimexpr0.5\dimexpr\macro,\dimexpr0.5\dimexpr\macro)--(segmentation.north);},
]
Upper
\tcblower
\quad This is the lower part.
\end{tcolorbox}
\end{document}
当然,如果盒子太大,看起来就不太好看。Ignasi 的解决方案没有给出直角,但对于不同的高度更稳定。
答案2
像这样?
\documentclass[12pt,a4paper]{article}
\usepackage[most]{tcolorbox}
%\tcbuselibrary{skins}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tcolorbox}[
enhanced,
lefthand width=3em,
arc=3mm,
boxrule=0pt,sidebyside,enhanced,
colback=green!60,
bicolor,colbacklower=gray,
collower=white,
underlay={
\path[fill=green!60]
(segmentation.south) -- ([xshift=5mm]segmentation.center)--(segmentation.north)--cycle;},
]
Upper
\tcblower
\quad This is the lower part.
\end{tcolorbox}
\end{document}
更新:
可以在calc
tikzlibrary 的帮助下绘制与框高度成比例的箭头。
\documentclass[12pt,a4paper]{article}
\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}
\usepackage{lipsum}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newtcolorbox{mybox}[1][]{%
enhanced,
lefthand width=3em,
arc=3mm,
boxrule=0pt,sidebyside,enhanced,
colback=green!60,
bicolor,
colbacklower=gray,
collower=white,
underlay={
\path[fill=green!60]
let \p1=($(segmentation.north)-(segmentation.south)$),
\n2={veclen(\x1,\y1)} in
(segmentation.south) --
([xshift=\n2/2]segmentation.center) --
(segmentation.north)
{[rounded corners]-|(frame.west)|-(segmentation.south)}--
cycle;},
#1
}
\begin{document}
\begin{mybox}
Upper
\tcblower
\quad \lipsum[2]
\end{mybox}
\begin{mybox}
Upper
\tcblower
\quad This is one sentence
\end{mybox}
\end{document}