我正在尝试在 Hearder 中创建如下所示的表:
但随着我的关注
代码:
\documentclass{article}
\usepackage[margin=1in,top=0.5in,headheight=5\baselineskip,headsep=1\baselineskip,includehead]{geometry}
\usepackage{tabularx}
\usepackage{graphicx}
%create table =============================================================================================================================
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{lastpage}
\usepackage{lipsum}
\usepackage{array}
\usepackage{multirow}
\usepackage{colortbl}
\usepackage{longtable}
\definecolor{MatlabCellColour}{RGB}{252,251,220}
\newcolumntype{A}[2]{%
>{\minipage{\dimexpr#1\linewidth-2\tabcolsep-#2\arrayrulewidth\relax}\vspace\tabcolsep}%
c<{\vspace\tabcolsep\endminipage}}
\newenvironment{Table}[4]{%
\longtable{%
|A{#1}{1.5}% for figure
|>{\centering$\displaystyle}A{#2}{1}<{$}% for inline equation
|>{\correction{-1}\strut\[}A{#3}{1}<{\]\strut}% for displayed equation
|>{\centering}A{#4}{1.5}% for text
|}\hline\ignorespaces}{%
\endlongtable\ignorespacesafterend}
%% some invisible "struts" to help define the structures and row heights.
%% set up and width for the tabularx environment to expand and fit to.
\newlength{\headerwidth}
\setlength{\headerwidth}{\textwidth}
\newsavebox{\myheader}
\begin{lrbox}{\myheader}%
\begin{minipage}[b]{\headerwidth}
\noindent
\longtable{|A{0.2}{1.5}|A{0.2}{1.5}||A{0.2}{1.5}|A{0.2}{1.5}|}\arrayrulecolor{green}\hline\hline
\rowcolor{MatlabCellColour} \multicolumn{1}{|A{0.3}{1}|}{\centering Author }& \multicolumn{3}{|A{0.7}{1}|}{ \centering Universität der Mathematik Department of Mathematics }\tabularnewline\hline\hline
\multicolumn{1}{|A{0.2}{1}|}{ \textbf{Page \thepage \ of \ \pageref{LastPage} } } & \multicolumn{1}{|A{0.2}{1}|}{\centering Subject } & \multicolumn{1}{|A{0.2}{1}|}{ \centering Year } & \multicolumn{1}{|A{0.3}{1}|}{\centering Mathematics competitions }\tabularnewline\hline
\endlongtable
\vspace{-0.5ex}\par
\bfseries
Time: 120 Min \hspace*{\fill}
Date: \hspace*{\fill}
Marks:40
\bigskip
\end{minipage}
\bigskip
\end{lrbox}
%% Setting up the header
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\lhead{}
\chead{\usebox{\myheader}}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{}
\begin{document}
\noindent
\longtable{|A{0.2}{1.5}|A{0.2}{1.5}||A{0.2}{1.5}|A{0.2}{1.5}|}\arrayrulecolor{green}\hline\hline
\rowcolor{MatlabCellColour} \multicolumn{1}{|A{0.3}{1}|}{\centering Author }& \multicolumn{3}{|A{0.7}{1}|}{ \centering Universität der Mathematik Department of Mathematics }\tabularnewline\hline\hline
\multicolumn{1}{|A{0.2}{1}|}{ \textbf{Page \thepage \ of \ \pageref{LastPage} } } & \multicolumn{1}{|A{0.2}{1}|}{\centering Subject } & \multicolumn{1}{|A{0.2}{1}|}{ \centering Year } & \multicolumn{1}{|A{0.3}{1}|}{\centering Mathematics competitions }\tabularnewline\hline
\endlongtable
\vspace{-0.5ex}\par
\bfseries
Time: 120 Min \hspace*{\fill}
Date: \hspace*{\fill}
Marks:40
\bigskip
\lipsum[1]
\newpage
\lipsum[1]
\end{document}
我懂了
- 有人能提供任何解决方案或建议吗?
答案1
这次使用另一个代码tabulary
,但主要思想是相同的“保持简单”原则。
\documentclass{article}
\usepackage[margin=1in,top=0.5in,headheight=7\baselineskip,
headsep=1.5\baselineskip,includehead]{geometry}
\usepackage{tabulary}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{lipsum}
\usepackage{xcolor,colortbl}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\chead{
\renewcommand{\arraystretch}{2.5}
\tabcolsep3em
\arrayrulecolor{green!70!black}
\begin{tabulary}{\linewidth}{|C|C|C|C|}
\hline\rowcolor{yellow!15}
Author & \multicolumn{3}{c|}{%
Universität der Mathematik Department of Mathematics}\\
\hline\bfseries
Page \thepage\ of \pageref{LastPage} &
Subject &
Year &
Mathematics competitions\\
\hline
\end{tabulary}
\linebreak\vskip2ex\bfseries
Time: 120 Min \hfill Date: \hfill Marks: 40}
\begin{document}
\lipsum[1]
\end{document}
答案2
以下代码几乎与第一张图片中显示的内容完全相同。
请注意,没有使用 savevox。保存框实际上就像拍一张照片,并在每次使用框时打印该照片。也就是说,引用不起作用。
\documentclass{article}
\usepackage[margin=1in,top=0.5in,headheight=5\baselineskip,headsep=1\baselineskip,includehead,
%showframe
]{geometry}
\usepackage{lastpage}
\usepackage{blindtext}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\definecolor{MatlabCellColour}{RGB}{252,251,220}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}p{#1}}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[CO,CE]{%
\arrayrulecolor{green!70!black}
\renewcommand{\arraystretch}{1.2}
\renewcommand{\arrayrulewidth}{.6pt}
\begin{tabularx}{\textwidth}{|X|X|X|X|}
\hline
\rowcolor{MatlabCellColour}Author & \multicolumn{3}{c|}{Universit\"at der Mathematik Department of Mathematics }\\
\hline
\bfseries Page \thepage~of~\pageref{LastPage}&Subject&Year&Other text\\
\hline
\end{tabularx}
\bigbreak
\bfseries
Time: 120 Min \hspace*{\fill}
Date: \hspace*{\fill}
Marks: 40
}
\begin{document}
\noindent
\blindtext[10]
\end{document}