3

I am trying to generate a template like this, a border and a table-like header and footer for all pages

enter image description here

Here is the code that I put together

\documentclass[a4paper]{article}

\usepackage[
top=25.4mm,
bottom=25.4mm,
left=25.4mm,
right=25.4mm
]{geometry}

\usepackage{tikz}

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
%This is to draw a rectangle as border
\fancyhead[L]{\tikz[overlay, remember picture] {
\draw ([shift={(24pt,-24pt)}]current page.north west) rectangle ++(544pt,-794pt);
%This is to draw the table
\begin{tabular}{|m{3.0cm}|m{10.0cm}|m{2.5cm}|}
      \hline
        \multicolumn{2}{|l|}{Photometry and Radiometry Calibration Document} \\ \hline
        PAR 117  & 
\begin{tabular}[c]{@{}l@{}}Revision\\ Issue
\end{tabular}
\\ \hline
\end{tabular}
} }

Note that I am drawing a rectangle in the header as the border for all pages, but I either get the border or the tables and not both at the same time.

Can someone fix the issue or give a tip? Thanks

4
  • Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code. – user30471 Aug 12 '20 at 2:20
  • @Andrew : Thanks for your comment and answer. I just added all my code. – Amin R. Aug 12 '20 at 13:04
  • I prefer everypage and tikzpagenodes for elaborate headers, especially if they don't match \textwidth. See tex.stackexchange.com/questions/276358/… for example. – John Kormylo Aug 12 '20 at 13:53
  • See tex.stackexchange.com/questions/385252/…. Your question is pretty much duplicate to it. – Zarko Aug 14 '20 at 3:33
1
+100

This is an example using tikz-page. You can use macros instead of fixed test inside header/footer to make it more handy.

enter image description here

\documentclass{article}
% set top/bottom margin to adjust text space
\usepackage[margin=1in, top=1.6in, bottom=1.2in]{geometry}
\usepackage{newtxtext}
\usepackage{array}
\usepackage{tikz}
\usepackage{tikz-page}
\usepackage{blindtext}
\usepackage{datetime2}
\usepackage{lastpage}

\usetikzlibrary{calc}

% border line style
\tikzset{
    pageborder/.style={line width=0.5mm},
    plainnode/.style={inner sep=0mm, outer sep=0mm}
}

% no header line
\renewcommand{\headrulewidth}{0pt}

% add paddings to cells
\newcommand\myvertspacea{\vspace*{1ex}}
\newcommand\mystructa{\rule{0pt}{2.6ex}}
\newcommand\myvertspaceb{\vspace*{2ex}}

% set page layout
\newcommand{\tikzpagelayout}{
    % move anchors a little bit for better borders
    \coordinate (newnorthwest) at ($(page.northwest)+(0.1mm, -0.1mm)$);
    \coordinate (newnortheast) at ($(page.northeast)+(-0.2mm, -0.1mm)$);
    \coordinate (newsouthwest) at ($(page.southwest)+(0.1mm, 0.1mm)$);
    \coordinate (newsoutheast) at ($(page.southeast)+(-0.2mm, 0.1mm)$);

    % draw border
    \draw[pageborder] (newnorthwest) -- (newsouthwest) -- (newsoutheast) 
        -- (newnortheast) -- (newnorthwest);
        
    % draw header
    % use yshift to lower the table a bit
    \node[plainnode, text width=0.9\linewidth, yshift=-2cm] at (page.north) {
    \centering
    \begin{tabular}{|c|c|}
        \hline
        \multicolumn{2}{|>{\centering}m{0.9\linewidth}|}{%
        \bgroup\bfseries\large\myvertspacea
        Photometry and Raiometry\\ Calibration Document \egroup} \\ \hline
        \multicolumn{1}{|>{\centering}m{0.6\linewidth}|}{%
            \textbf{PAR-117} Spectral Irridiance Standards: Operating Procedure\\
            (A33-06-04-01 to A33-06-04-04)} 
            & \multicolumn{1}{p{0.3\linewidth}|}{%
            \begin{tabular}{>{\bfseries}ll}
            \mystructa Revision: & 1.6\\
            Issue Date: & 1999-Apr-09\\
            Issued By: & AAG\\
            Effective: & 2009-Jun-30
            \end{tabular}
        }\\ \hline
    \end{tabular}
    \par
    };
    
    
    % draw footer
    \node[plainnode, text width=0.9\linewidth, yshift=2cm] at (page.south) {
        \centering
        \bgroup
        \small
        \begin{tabular}{|m{0.35\linewidth}|p{0.35\linewidth}|c|}
        \hline
        \myvertspaceb\textbf{Approved by:}\myvertspaceb
        & \textbf{Date:}  
        & \multicolumn{1}{p{0.2\linewidth}|}{\centering\textbf{Page \thepage\ of \pageref{LastPage}}} \\ \hline
        \end{tabular}
        \egroup
        };

}
\pagestyle{plain}

\begin{document}

\Blindtext[10]
\end{document}
4

I am not sure that you need tikz for this as I think that the fancyhdr package and a few tabular environments suffice to produce:

enter image description here

Here is the code:

\documentclass{article}
\usepackage{array}
\usepackage{fancyhdr}
\usepackage{etoolbox}
% remember the number of the last page
\AtEndDocument{\label{P:LastPage}}

% placeholder commands for data in the header and footer
\providecommand\Unit{PAR-117}
\providecommand\Description{Spectral Irradiance Standards:\newline Operating procedure\newline(A33-06-04-01 to A33-06-04-04)}
\providecommand\Revision{1.6}
\providecommand\IssueDate{1999-Apr-09}
\providecommand\IssuedBy{AAG}
\providecommand\Effective{2009-Jun-30}
\providecommand\ApprovedBy{The Supreme Approver}
\providecommand\ApprovalDate{2016-11-12}

% the header and footer
\setlength\arrayrulewidth{1pt}
\newcommand\HeadStrut{\vrule height 2em depth 1.5em width 0pt}
\pagestyle{fancy}
\fancyhf{}
%This is to draw a rectangle as border
\renewcommand\headrule{} % disable header rule
\fancyhead[C]{%
  \begin{tabular}{|m{0.60\textwidth}|m{0.35\textwidth}|}\hline
    \multicolumn{2}{|c|}{\bfseries\large Photometry and Radiometry Calibration Document\HeadStrut}\\
    \hline
    \begin{tabular}{lm{75mm}}
         \bfseries\Unit & \Description
    \end{tabular}
    &
    \begin{tabular}{@{}ll@{}}
        \textbf{Revision:}  & \Revision\\
        \textbf{Issue date} & \IssueDate\\
        \textbf{Issued by:} & \IssuedBy\\
        \textbf{Effective}  & \Effective\\
    \end{tabular}
    \\ \hline
  \end{tabular}
}
\fancyfoot[C]{
  \begin{tabular}{|m{0.5\textwidth}|m{0.2\textwidth}|m{0.2\textwidth}|}\hline
     \textbf{Approved by:}~\ApprovedBy &
     \textbf{Date:}~\ApprovalDate &
     Page \thepage~of~\pageref{P:LastPage}\\
     \hline
  \end{tabular}
}
\begin{document}
  blah
  \newpage
  blah
\end{document}

In particular, I have defined the following 'placeholder commands' at the top of the document for the data in the header and footer.

\providecommand\Unit{PAR-117}
\providecommand\Description{Spectral Irradiance Standards:\newline Operating procedure\newline(A33-06-04-01 to A33-06-04-04)}
\providecommand\Revision{1.6}
\providecommand\IssueDate{1999-Apr-09}
\providecommand\IssuedBy{AAG}
\providecommand\Effective{2009-Jun-30}
\providecommand\ApprovedBy{The Supreme Approver}
\providecommand\ApprovalDate{2016-11-12}
1
  • Thanks Andrew. Apparently I did not clearly explain my issue. I am drawing a rectangle as the page border + a table in the header. I guess you did not get that part so your code is not drawing border and this is why I used tikz package. – Amin R. Aug 12 '20 at 15:04

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.