0

I need to insert a fairly tall header on every sheet of paper (a table where the students can write their name and some other stuff) of a multiple-page exam, but I only need them to do it on one side of the paper.

I have managed to only have the header on odd pages using \header{}{\oddeven{ \my_header}{}}{} and got to fit into the page using \extraheadheight{35mm}. However, this causes a large blank space on even pages, which I would like to use for regular content. Is there a reasonable way to achieve this?

\documentclass[a4paper]{exam}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell}
\usepackage{lipsum}

\begin{document}
    \def\my_header{{
            \centering
            \renewcommand{\arraystretch}{1.3}
            \begin{tabular}{|>{\centering}m{\dimexpr 30mm - 2\tabcolsep}|>{\raggedright}m{\dimexpr 58mm - 2\tabcolsep}|>{\raggedright}m{\dimexpr 50mm - 2\tabcolsep}|>{\centering}m{\dimexpr 20mm - 2\tabcolsep}|}
                \hline 
                \multirow{4}{*}{\centering Here goes a logo} & \multicolumn{2}{c|}{
                    \makecell{\large Title \\ \footnotesize Subtitle}
                    
                } & Some code\tabularnewline
                \cline{2-4} \cline{3-4} \cline{4-4} 
                & \multicolumn{2}{l|}{Foo:} & \multirow{3}{*}{}\tabularnewline
                \cline{2-3} \cline{3-3} 
                & Bar: & Baz: & \tabularnewline
                \cline{2-3} \cline{3-3} 
                & \multicolumn{2}{c|}{More info} & \tabularnewline
                \hline 
            \end{tabular}
    }}
    
    \header{}{\oddeven{ \my_header}{}}{}
    \extraheadheight{35mm}
    
    
    \lipsum[1-29]
    
\end{document}
2
  • Welcome to TeX.SE! Please show us a short compilable TeX code resluting in your issue. Then we do not have to guess what you are doing ...
    – Mensch
    Commented Jun 22, 2022 at 18:16
  • Yes, sorry, in my head it was clear but you are right it is easier with an example. Edited, thanks. :) Commented Jun 22, 2022 at 21:37

1 Answer 1

0

This uses an \afterpage loop to add the "header" inside the text area on odd pages. It is terminated by \endheadertrue.

I used a savebox so it wouldn't have to be reformatted every page.

\documentclass[a4paper]{exam}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell}
\usepackage{lipsum}

\pagestyle{empty}% no room for footer anyway

\newsavebox{\myheader}
\savebox\myheader{\parbox{\textwidth}{%
            \centering
            \renewcommand{\arraystretch}{1.3}
            \begin{tabular}{|>{\centering}m{\dimexpr 30mm - 2\tabcolsep}|>{\raggedright}m{\dimexpr 58mm - 2\tabcolsep}|>{\raggedright}m{\dimexpr 50mm - 2\tabcolsep}|>{\centering}m{\dimexpr 20mm - 2\tabcolsep}|}
                \hline 
                \multirow{4}{*}{\centering Here goes a logo} & \multicolumn{2}{c|}{
                    \makecell{\large Title \\ \footnotesize Subtitle}
                    
                } & Some code\tabularnewline
                \cline{2-4} \cline{3-4} \cline{4-4} 
                & \multicolumn{2}{l|}{Foo:} & \multirow{3}{*}{}\tabularnewline
                \cline{2-3} \cline{3-3} 
                & Bar: & Baz: & \tabularnewline
                \cline{2-3} \cline{3-3} 
                & \multicolumn{2}{c|}{More info} & \tabularnewline
                \hline 
            \end{tabular}%
    \vskip\headsep}}

\newif\ifendheader

\usepackage{afterpage}

\newcommand{\checkpage}{\ifendheader\else
  \ifodd\value{page}\noindent\usebox\myheader \fi
  \afterpage{\checkpage}\fi}

\begin{document}
\noindent\usebox\myheader
\afterpage{\checkpage}

    
    \lipsum[1-29]

\endheadertrue% \AtEndDocument too slow
\end{document}

This version uses the flowfram package. Odd and even pages are different heights, and the "header" is a separate area altogether.

\documentclass[a4paper]{exam}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell}
\usepackage{lipsum}

\pagestyle{empty}% no room for footer anyway

\newsavebox{\myheader}
\savebox\myheader{\parbox{\textwidth}{%
            \centering
            \renewcommand{\arraystretch}{1.3}
            \begin{tabular}{|>{\centering}m{\dimexpr 30mm - 2\tabcolsep}|>{\raggedright}m{\dimexpr 58mm - 2\tabcolsep}|>{\raggedright}m{\dimexpr 50mm - 2\tabcolsep}|>{\centering}m{\dimexpr 20mm - 2\tabcolsep}|}
                \hline 
                \multirow{4}{*}{\centering Here goes a logo} & \multicolumn{2}{c|}{
                    \makecell{\large Title \\ \footnotesize Subtitle}
                    
                } & Some code\tabularnewline
                \cline{2-4} \cline{3-4} \cline{4-4} 
                & \multicolumn{2}{l|}{Foo:} & \multirow{3}{*}{}\tabularnewline
                \cline{2-3} \cline{3-3} 
                & Bar: & Baz: & \tabularnewline
                \cline{2-3} \cline{3-3} 
                & \multicolumn{2}{c|}{More info} & \tabularnewline
                \hline 
            \end{tabular}%
    \vskip\headsep}}

\usepackage{flowfram}

\newstaticframe[odd]{\wd\myheader}{\dimexpr \ht\myheader+\dp\myheader}{0pt}%
  {\dimexpr \textheight-\ht\myheader-\dp\myheader}
\begin{staticcontents}{1}% IDN=1
  \usebox\myheader
\end{staticcontents}

\newflowframe[odd]{\textwidth}{\dimexpr \textheight-\ht\myheader-\dp\myheader}{0pt}{0pt}
\newflowframe[even]{\textwidth}{\dimexpr \textheight}{0pt}{0pt}

\begin{document}
    
    \lipsum[1-29]

\end{document}
5
  • I'm not really an expert on LaTeX, so I get the feel that these are somewhat bypassing the mechanisms of the exam class for headers, right? At any rate, both solutions look perfectly suitable for my needs, so thank you very, very much. :) Commented Jun 23, 2022 at 10:30
  • Headers, by definition, are placed ABOVE the text area. Even flowfram doesn't actually change the top of the text area between pages. Commented Jun 23, 2022 at 14:00
  • I'm not sure to actually grasp what you mean, what I understand from your comment is this: the position of the flowfram frames are referred to the dimensions of the basic text block and those are constant throughout the document and there is no way to dynamically alter them, is that it? Commented Jun 23, 2022 at 14:08
  • Yes, nor am I certain that exam class can handle changing margins even if you create them. Commented Jun 23, 2022 at 14:39
  • Understood, thank you very much for your help. Commented Jun 23, 2022 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .