我需要一个像这样的 tcbitemize 结构总高6cm。
我该如何设置,使第一行的高度仅为约 2 厘米?(第二行:“休息”。)
\documentclass{article}
\usepackage[showframe=true]{geometry}
\usepackage[most]{tcolorbox}
\tcbset{
SymbolStyle/.style={boxrule=4pt,colframe=blue},
NoGaps/.style={boxsep=0pt,
left=0pt, right=0pt, top=0pt, bottom=0pt,},
}
\begin{document}
\begin{tcolorbox}[
colframe=red, boxrule=2pt,
NoGaps,
]
\begin{tcbitemize}[
% Problem here ======================
%row 1/.style={height=2cm,}, % no effect
raster height=6cm, % raster rows=2,
raster equal height=rows,
% ===============================
sharp corners, boxrule=1pt,
NoGaps, boxsep=3pt,
raster columns=100,
raster column skip=0pt,
raster row skip=0pt,
colback=white
]
\tcbitem[raster multicolumn=25, SymbolStyle,
%height=4cm % no effect
] X
\tcbitem[raster multicolumn=15] Y
\tcbitem[raster multicolumn=60] Z
\tcbitem[raster multicolumn=60] a \\ 1 \\ 2\\ 3 \\ 4\\ 5 \\ 6 \\ 7 \\8
\tcbitem[raster multicolumn=40] b
\end{tcbitemize}
\end{tcolorbox}
\end{document}
答案1
指定第一行高度的选项名为raster row 1
,而不是row 1
。选项tcb/raster row m
记录在记录tcolorbox
,第 15.4 节。
\documentclass{article}
\usepackage[showframe=true]{geometry}
\usepackage[most]{tcolorbox}
\tcbset{
SymbolStyle/.style={boxrule=4pt, colframe=blue},
NoGaps/.style={boxsep=0pt, left=0pt, right=0pt, top=0pt, bottom=0pt},
draw height/.style={
enhanced,
finish={
\draw[blue,very thick,<->]
(frame.south) -- node[right,pos=.75] {#1} +(0,#1);
}
}
}
\begin{document}
\begin{tcolorbox}[
colframe=red, boxrule=2pt,
NoGaps,
height=6cm,
draw height=6cm
]
\begin{tcbitemize}[
enhanced,
raster row 1/.style={height=2cm},
% 4pt = doubled the width of outer boxrule
raster row 2/.style={height=4cm-4pt},
raster equal height=rows,
sharp corners, boxrule=1pt,
NoGaps, boxsep=3pt,
raster columns=100,
raster column skip=0pt,
raster row skip=0pt,
raster before skip=0pt,
raster after skip=0pt,
colback=white,
]
\tcbitem[raster multicolumn=25, SymbolStyle] X
\tcbitem[raster multicolumn=15] Y
\tcbitem[raster multicolumn=60, draw height=2cm] Z
\tcbitem[raster multicolumn=60] a \\ 1 \\ 2\\ 3 \\ 4\\ 5 \\ 6 \\ 7 \\8
\tcbitem[raster multicolumn=40] b
\end{tcbitemize}
\end{tcolorbox}
\end{document}
该选项draw height
仅用于绘制测量箭头,您可以在实际使用中安全地将其删除。
答案2
这种不规则结构可以通过 轻松获得tcbposter
(也可以从tcolorbox
这样的包中获得tcbraster
)。虽然海报应该具有规则的结构,但可以更改所有框的高度、宽度和位置。甚至可以定义框,其高度由其他框之间的空间决定。
以下代码显示了如何使用 获得所需的结构tcbposter
。在这种情况下,使用一列两行的海报作为主要结构。span
选项可以定义每个框的宽度,而column=1
、column*=1
和xshift
用于固定框的水平位置。第一行框定义为,below=top
因为这样它们的高度由其内容或 tcolorboxheight
选项固定。第二行框定义为between = ... and bottom
填充所有剩余的垂直空间。
\documentclass{article}
\usepackage{geometry}
\usepackage[most]{tcolorbox}
\tcbset{
SymbolStyle/.style={boxrule=4pt,colframe=blue},
NoGaps/.style={boxsep=0pt, left=0pt, right=0pt, top=0pt, bottom=0pt},
}
\begin{document}
\begin{tcbposter}[
poster = {%showframe,
columns=1, rows = 2, spacing=0pt, height=6cm},
boxes = {sharp corners, colframe=red, boxrule=1pt, NoGaps, boxsep=3pt, colback=white, enhanced}
]
\posterbox[SymbolStyle, height=2cm]{name=X, column=1, below=top, span=.25}{X}
\posterbox[height=2cm]{name=Y, row=1, span=.15, xshift=.25\linewidth}{Y}
\posterbox[height=2cm]{name=Z, column*=1, span=.60, below=top}{Z}
\posterbox{name=a, between=X and bottom, span=.6, column=1}{a\\ 1\\ 2\\ 3\\ 4\\ 5\\ 6\\ 7\\ 8}
\posterbox{name=b, between=Z and bottom, span=.6, column*=1}{b}
\end{tcbposter}
\end{document}