如何在页眉上插入表格

如何在页眉上插入表格

我正在尝试在页眉上插入表格,就像下面的示例一样。我受此启发创建此页眉的整个文档可在此处找到Moshell 用户指南

所需输出的示例

在这张图片中,这是文档每一页的页眉。当然,页面可以根据页码而变化。

我已经创建了一个代码示例,它可以重现表格格式以及带有左侧徽标、中间文本和右侧页码的标题。

下面提供的代码示例:

\documentclass{memoir}
\usepackage[ a4paper , centering ]{geometry}
\usepackage{graphicx} % demo option just for the example
\usepackage{lipsum} % demo option just for text
\usepackage{lastpage} % include last page numbering
\usepackage{chngpage} % allows for temporary adjustment of side margins
\usepackage{datetime}
\newdateformat{mydate}{\THEYEAR-\twodigit{\THEMONTH}-\twodigit{\THEDAY}}

\makepagestyle{mystyle}
\makeevenhead{mystyle}{\includegraphics[height=20pt]{LaTeX_logo}}{\hspace{3cm}Informational\\\hspace{3.1cm} USER GUIDE}{\thepage(\pageref{LastPage})}
\makeoddhead{mystyle}{\includegraphics[height=20pt]{LaTeX_logo}}{\hspace{3cm}Informational\\\hspace{3.1cm} USER GUIDE}{\thepage(\pageref{LastPage})}

\pagestyle{mystyle}
\begin{document}

\begin{table}
  \begin{adjustwidth}{-1in}{-1in}  
    \begin{center}
      \begin{tabular}{|l|l|l|l|l|l|} 
      \hline
      \multicolumn{3}{|l}{{\small\textbf{Prepared (subject responsible)}}} & \multicolumn{3}{|l|}{{\small\textbf{No.}}} \\
      \multicolumn{3}{|l}{Thanos 1 \& Thanos 2} & \multicolumn{3}{|l|}{1553-CXC1328930} \\ \hline
      \multicolumn{1}{|l}{{\small\textbf{Approved (Document responsible)}}} & & \multicolumn{1}{l}{{\small\textbf{Checked}}} & \multicolumn{1}{|l}{{\small\textbf{Date}}} & \multicolumn{1}{|l|}{{\small\textbf{Rev.}}} & \multicolumn{1}{l|}{{\small\textbf{Reference}}} \\
      \multicolumn{1}{|l}{ } & \multicolumn{1}{l}{ } & \multicolumn{1}{l}{ } & \multicolumn{1}{|l}{\mydate\today} & \multicolumn{1}{l}{J} & \multicolumn{1}{l|}{Thanos\_UserGuide.tex} \\ \hline
      \end{tabular}
    \end{center}
  \end{adjustwidth}
\end{table}

\tableofcontents
\listoffigures
\listoftables

\lipsum[1-20]

\end{document} 

我希望页眉从第一页开始。不幸的是,在我的代码中,由于目录、图片列表和表格列表,页眉从第二页开始。我使用的是回忆录课因为我认为这是最正确的方法来解决我的问题,但也许其他课程也可以做到。提前感谢您的时间和精力。

答案1

方案如下:表格作为页眉的中心字段插入,作为零宽度框。若要将其放在所有页面中,请使用

\aliaspagestyle{plain}{mystyle}

因此也将在请求的页面中memoir使用。可以在编译一次并在文件中查找消息后设置头部高度,例如mystyleplain.log

Class memoir Warning: The material used in the headers is too large
(73.19998pt) for the given head height (50.0pt), it is recommended to
either increase the head height or redesign the header
(in both cases you will find help in the memoir manual).

以下是代码。请注意,整个标头是一个tabular

\documentclass{memoir}
\usepackage[a4paper,centering,headheight=75pt]{geometry}
\usepackage[demo]{graphicx} % demo option just for the example
\usepackage{lipsum} % demo option just for text
\usepackage{lastpage} % include last page numbering
\usepackage{chngpage} % allows for temporary adjustment of side margins
\usepackage{datetime}
\newdateformat{mydate}{\THEYEAR-\twodigit{\THEMONTH}-\twodigit{\THEDAY}}

\makepagestyle{mystyle}
\makeevenhead{mystyle}{}{\thanoshead}{}
\makeoddhead{mystyle}{}{\thanoshead}{}

\newcommand{\thanoshead}{%
  \makebox[0pt]{%
    \begin{tabular}{|l|l|l|l|l|l|}
    \multicolumn{3}{@{}l}{\includegraphics[height=20pt]{LOGO}} &
      \multicolumn{2}{l}{\begin{tabular}[b]{@{}l@{}}Informational\\USER GUIDE\end{tabular}} &
      \multicolumn{1}{r@{}}{\thepage(\pageref{LastPage})} \\
    \hline
    \multicolumn{3}{|l|}{\small\textbf{Prepared (subject responsible)}} &
      \multicolumn{3}{l|}{\small\textbf{No.}} \\
    \multicolumn{3}{|l|}{Thanos 1 \& Thanos 2} &
      \multicolumn{3}{l|}{1553-CXC1328930} \\
    \hline
    \small\textbf{Approved (Document responsible)} & &
    \small\textbf{Checked} & \small\textbf{Date} &
      \small\textbf{Rev.} & \small\textbf{Reference} \\
    & & & \mydate\today & J & Thanos\_UserGuide.tex \\
    \hline
    \end{tabular}%
  }%
}

\pagestyle{mystyle}
\aliaspagestyle{plain}{mystyle}

\begin{document}

\tableofcontents
\listoffigures
\listoftables

\lipsum[1-20]

\end{document} 

在此处输入图片描述

答案2

我已经这样做了,book因为无论如何你都要覆盖的memoir页面布局,而且这样做更简单,而不需要定义三部分标题。

我用来fancyhdr配置标题。我读取输出以确定标题高度需要为多少,以便我可以将其提供给geometry

由于您希望每页都有页眉,我只需重新定义样式plain并使用即可。demo由于我没有您的徽标文件,因此我使用了模式,并且我稍微整理了一下表格。

\documentclass[a4paper]{book}
\usepackage[centering, headheight=80pt]{geometry}
\usepackage[demo]{graphicx} % demo option just for the example
\usepackage{lipsum} % demo option just for text
\usepackage{lastpage} % include last page numbering
\usepackage{datetime,array,fancyhdr}
\newdateformat{mydate}{\THEYEAR-\twodigit{\THEMONTH}-\twodigit{\THEDAY}}

\newsavebox{\mytabularheader}
\newsavebox{\mytabularheadertitle}
\sbox{\mytabularheadertitle}{%
  \begin{minipage}[b]{.175\textwidth}
    Informational\\USER GUIDE
  \end{minipage}}

\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \fancyhf[ch]{\usebox{\mytabularheader}}}

\pagestyle{plain}
\begin{document}

\sbox{\mytabularheader}{%
  \begin{minipage}{\textwidth}
    \centering
    \begin{tabular}{|*{6}{>{\small}l|}}
      \multicolumn{3}{l}{\includegraphics[height=20pt]{example-image-a}} & \multicolumn{2}{l}{\usebox{\mytabularheadertitle}} & \multicolumn{1}{r}{\thepage(\pageref{LastPage})}\\[.25em]
      \hline
      \multicolumn{3}{|>{\small}l}{\textbf{Prepared (subject responsible)}} & \multicolumn{3}{|>{\small}l|}{\textbf{No.}} \\
      \multicolumn{3}{|>{\small}l}{Thanos 1 \& Thanos 2} & \multicolumn{3}{|>{\small}l|}{1553-CXC1328930} \\ \hline
      \multicolumn{2}{|>{\small}l|}{\textbf{Approved (Document responsible)}}  & \textbf{Checked} & \textbf{Date} & \textbf{Rev.} & \textbf{Reference} \\
      \multicolumn{2}{|>{\small}l|}{} &  & \mydate\today & J & Thanos\_UserGuide.tex \\ \hline
    \end{tabular}
  \end{minipage}}

  \tableofcontents
  \listoffigures
  \listoftables

  \lipsum[1-20]

\end{document}

表格页

相关内容