使用 tcolorbox 功能将页面分成更小的部分

使用 tcolorbox 功能将页面分成更小的部分

我想要一张 A4 大小的纸,将其分成 8 个相等的部分,每个部分都具有 tcolorbox 包的功能。使用以下代码关于 TeX.SE 的其他问题,我已经准备好了,但是框的高度固定为文本的高度而不是小部分的大小。

对我来说,各个方向的边距相等很重要,并且我不希望加载额外的包裹。

%pdflatex

\documentclass[a4paper]{article}
\usepackage[margin=5mm,centering,landscape]{geometry}
\usepackage{tcolorbox}
\newcommand\Block[2]{%
\setlength\fboxsep{0pt}\setlength\fboxrule{0.1pt}% delete
\fbox{% delete
\begin{minipage}[c][\dimexpr.5\textheight\relax][c]{\dimexpr0.25\textwidth-3pt\relax}
\centering
\par \begin{tcolorbox}[colback=red!5!white,
colframe=red!75!black,
sharp corners=northwest ,title=#1]
#2
\end{tcolorbox}

\end{minipage}%
  }% delete
}

\begin{document}
\thispagestyle{empty}% optional: suppress page numbering

\noindent
\Block{text}{caption}\hfill%
\Block{text}{caption}\hfill%
\Block{text}{caption}\hfill%
\Block{text}{caption}%
\vfill
\noindent
\Block{text}{caption}\hfill%
\Block{text}{caption}\hfill%
\Block{text}{caption}\hfill%
\Block{text}{caption}
\end{document}

在此处输入图片描述

答案1

两种可能的方法。第一种方法使用 minipages,就像原始代码那样。在第二部分中,我使用它tcbraster来帮助定位。

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage[margin=5mm,centering,landscape]{geometry}
\usepackage[most]{tcolorbox}
\newcommand\Block[2]{
\begin{minipage}[c][\dimexpr.5\textheight\relax][c]{\dimexpr0.25\textwidth-3pt\relax}
\centering
\par \begin{tcolorbox}[colback=red!5!white,
                       colframe=red!75!black,
                       sharp corners=northwest,
                       title=#1, 
                       height=\dimexpr.5\textheight\relax]
#2
\end{tcolorbox}
\end{minipage}%
}


\newcommand\BlockAlt[2]{%
\begin{tcolorbox}[colback=red!5!white,
                  colframe=red!75!black,
                  sharp corners=northwest,
                  title=#1, 
                  height=\dimexpr.5\textheight-5pt\relax]
#2
\end{tcolorbox}
}

\begin{document}
\thispagestyle{empty}% optional: suppress page numbering

\noindent
\Block{text}{caption}\hfill%
\Block{text}{caption}\hfill%
\Block{text}{caption}\hfill%
\Block{text}{caption}%
\vfill
\noindent
\Block{text}{caption}\hfill%
\Block{text}{caption}\hfill%
\Block{text}{caption}\hfill%
\Block{text}{caption}

\newpage

\begin{tcbraster}[raster columns=4,raster equal height, raster column skip=5pt]
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\end{tcbraster}
\end{document}

\documentclass[a4paper]{article}
\usepackage[margin=5mm,centering,landscape]{geometry}
\usepackage[most]{tcolorbox}

\newcommand\BlockAlt[2]{%
\begin{tcolorbox}[colback=red!5!white,
                  colframe=red!75!black,
                  sharp corners=northwest,
                  title=#1, 
                  height=3cm] %<---- changed to 3 cm
#2
\end{tcolorbox}
}

\begin{document}
\thispagestyle{empty}% optional: suppress page numbering

\begin{tcbraster}[raster columns=3, %<--- changed to 3, so only 3 boxes will be in one row
                  raster equal height, 
                  raster column skip=2cm, % <--- changed to 2 cm, will make boxes narrower
                  raster row skip=2cm] %<--- added and also set to 2cm for equal spacing around the boxes
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\BlockAlt{text}{caption}%
\end{tcbraster}
\end{document}

在此处输入图片描述

相关内容