自动计算标题大小

自动计算标题大小

我正在寻找一个占位符/计算/代码片段,作为几何包中 LaTeX 文档的头部高度值:

\usepackage[inner=1cm,outer=1cm,top=1cm,bottom=1cm,
        includeheadfoot,
        headheight=<Code-I-am-looking-for>
        ]{geometry}

之所以有这个特殊要求,是因为我不知道页眉中的文本内容量(或者至少不知道最终的页眉大小),因为完整的 LaTeX 文件是生成的,因此我无法预测页眉中的文本将占用的行数。

我已经考虑过这个话题计算 fancyhdr 所需的头部高度,意外地不是线性的在写这个问题之前,但由于我的标题中没有行数,这不适合我的问题。

最小工作示例

\documentclass[a4paper,fontsize=8pt,pdftex,landscape]{scrbook}
\usepackage[inner=1cm,outer=1cm,top=1cm,bottom=1cm,
            includeheadfoot,% <-- added
            headheight=76.86pt,% <-- added
            showframe]{geometry}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
%\renewcommand*\oldstylenums[1]{\carlitoOsF #1}
%\usepackage[sfdefault,lf]{carlito}
\usepackage{multicol}
\usepackage[most]{tcolorbox}
%\usepackage{MnSymbol}

% changed to scrlayer-scrpage
\usepackage{scrlayer-scrpage}
\pagestyle{scrheadings}
% header
\ohead{}
\ihead{}
\chead{\begin{tcbraster}[raster columns=3]
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, adjusted title=Placeholder]
Placeholder box
\end{tcolorbox}
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, adjusted title=Placeholder]
Placeholder box with a long content that does push the boundaries of a one-liner
\end{tcolorbox}
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, adjusted title=Placeholder]
Placeholder box
\end{tcolorbox}
\end{tcbraster}
}
% footer
\ofoot{}
\ifoot{}
\cfoot{\pagemark}

\begin{document}
\Large
\begin{multicols*}{5}
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, , adjusted title=Placeholder]
Placeholder box
\end{tcolorbox}
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, , adjusted title=Placeholder]
Placeholder box
\end{tcolorbox}
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, , adjusted title=Placeholder]
Placeholder box
\end{tcolorbox}
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, , adjusted title=Placeholder]
Placeholder box
\end{tcolorbox}
\vspace*{\fill}% <-- added
\columnbreak
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, , adjusted title=Placeholder, height=7.2cm]
Placeholder box
\end{tcolorbox}
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, , adjusted title=Placeholder, height=7.2cm]
Placeholder box
\end{tcolorbox}
\newpage
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, , adjusted title=Placeholder, height=7.2cm]
Placeholder box
\end{tcolorbox}
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, , adjusted title=Placeholder, height=7.2cm]
Placeholder box
\end{tcolorbox}
\begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, , adjusted title=Placeholder, height=7.2cm]
Placeholder box
\end{tcolorbox}
\end{multicols*}
\end{document}

如需了解更多背景信息,请查看我最初的帖子

答案1

如果所有页面的页眉内容都是固定的,那么您可以将其保存到一个框中并测量其高度:

\documentclass[fontsize=8pt,landscape]{scrbook}
\usepackage[margin=1cm,
  showframe
]{geometry}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{multicol}
\usepackage[most]{tcolorbox}


\usepackage{scrlayer-scrpage}% sets pagestyle scrheadings automatically
\clearmainofpairofpagestyles
\chead{\usebox\headerbox}
\cfoot{\pagemark}

\newsavebox\headerbox
\AtBeginDocument{%
  \sbox\headerbox{%
    \usekomafont{pageheadfoot}\usekomafont{pagehead}%
    \begin{tcbraster}[raster columns=3]
      \begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, adjusted title=Placeholder]
        Placeholder box
      \end{tcolorbox}
      \begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, adjusted title=Placeholder]
        Placeholder box with a long content that does push the boundaries of a one-liner
      \end{tcolorbox}
      \begin{tcolorbox}[halign=center, center title, valign=center, equal height group=A, adjusted title=Placeholder]
        Placeholder box
      \end{tcolorbox}
    \end{tcbraster}%
  }%
  \newgeometry{margin=1cm,includeheadfoot,headheight=\dimexpr\ht\headerbox+\dp\headerbox+\dp\strutbox\relax}%
}

\usepackage{blindtext}% only for dummy text
\begin{document}
\Large
\Blindtext
\end{document}

在此处输入图片描述

相关内容