考试类别中偶数页和奇数页的页眉偏移不同

考试类别中偶数页和奇数页的页眉偏移不同

我需要在多页考试的每张纸上插入一个相当高的页眉(学生可以在一张桌子上写上他们的名字和其他一些内容),但我只需要他们在纸的一面做这件事。

我已设法使用 仅在奇数页上显示页眉,\header{}{\oddeven{ \my_header}{}}{}并使用 将其放入页面中\extraheadheight{35mm}。但是,这会导致偶数页上出现大量空白,我想将其用于常规内容。有没有合理的方法来实现这一点?

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

答案1

此代码使用\afterpage循环在奇数页的文本区域内添加“页眉”。代码以 结束\endheadertrue

我使用了保存箱,这样就不需要重新格式化每一页。

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

此版本使用 flowfram 包。奇数页和偶数页的高度不同,并且“页眉”是完全独立的区域。

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

相关内容