4

I'm looking for a placeholder/calculation/code-piece to put as the headheight value for a LaTeX document within the geometry package:

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

The reason for this special requirement is that I am not in knowledge of the amount of text content in the header (or not the resulting header size at least), because the complete LaTeX file is generated and thus I cannot predict the number of lines the text in the header will occupy.

I have considered the topic Calculating required headheight for fancyhdr, unexpectedly not linear preliminary to writing this question, but due to the fact that I don't have the number of lines within my header this does not suit my problem.

Minimum work example

\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}

For even more context please have a look at my initial post.

  • 1
    Is it possible to give the header contents to a special macro? So can I wrap the header setting in something like \addtomyheader{left}{center}{right}? Will a two-run solution be ok? Do you have to use fancyhdr or is KOMA's mechanism for headers fine, too? How are the headers to be set? Can you please give a minimal working example (MWE) in this question? – Skillmon Jun 14 '18 at 11:21
  • 2
    Do the headers change throughout the document or do they get set up once and stay? – Skillmon Jun 14 '18 at 11:36
  • @Skillmon Yes, the header content is fix after it was generated and is identical over all pages (if even necessary to have more than one). I added the MWE. A two-run is no option I think because I have no possibility of changing the latex document after it was generated – mgessenich Jun 14 '18 at 13:20
  • No wait, I think I can regex-search for the headheight and replace the headheight by the needed value.. but how to find that out? – mgessenich Jun 14 '18 at 13:32
  • A two run solution would be easily possible, as I could write something to the .aux file. I'd have done this combined with the wrapping macro if the header had been subject to changes, so that the first run would determine the maximum header size and every following run would use the size determined by the previous run. If the header doesn't change this is over complicating stuff. esdd's answer works in that case. – Skillmon Jun 15 '18 at 8:17
4

If the header content is fix for all pages, then you can save it into a box and measure up its height:

\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}

enter image description here

  • 1
    For generalization, perhaps it is clever to also include \dp\headerbox in the set headheight. – Skillmon Jun 15 '18 at 8:18
  • Nice! I'm curious what is done differently "underneath" so that this headerbox does produce no error (works the intended way) Do you have any knowledge on that? – mgessenich Jun 18 '18 at 8:49
  • The content of the header is fix. At the beginning of the document - before the first page starts - it is set to a box. The height and the depth of this box is used to adjust headheight before the first page starts. So \headheight is big enough that no warning is produced. – esdd Jun 18 '18 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.