TransWikia.com

How to draw a rectangle and table in the header together?

TeX - LaTeX Asked by Amin R. on January 15, 2021

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

2 Answers

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
newcommandmyvertspacea{vspace*{1ex}}
newcommandmystructa{rule{0pt}{2.6ex}}
newcommandmyvertspaceb{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.9linewidth, yshift=-2cm] at (page.north) {
    centering
    begin{tabular}{|c|c|}
        hline
        multicolumn{2}{|>{centering}m{0.9linewidth}|}{%
        bgroupbfserieslargemyvertspacea
        Photometry and Raiometry Calibration Document egroup}  hline
        multicolumn{1}{|>{centering}m{0.6linewidth}|}{%
            textbf{PAR-117} Spectral Irridiance Standards: Operating Procedure
            (A33-06-04-01 to A33-06-04-04)} 
            & multicolumn{1}{p{0.3linewidth}|}{%
            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.9linewidth, yshift=2cm] at (page.south) {
        centering
        bgroup
        small
        begin{tabular}{|m{0.35linewidth}|p{0.35linewidth}|c|}
        hline
        myvertspacebtextbf{Approved by:}myvertspaceb
        & textbf{Date:}  
        & multicolumn{1}{p{0.2linewidth}|}{centeringtextbf{Page thepage of pageref{LastPage}}}  hline
        end{tabular}
        egroup
        };

}
pagestyle{plain}

begin{document}

Blindtext[10]
end{document}

Correct answer by Alan Xiang on January 15, 2021

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
providecommandUnit{PAR-117}
providecommandDescription{Spectral Irradiance Standards:newline Operating procedurenewline(A33-06-04-01 to A33-06-04-04)}
providecommandRevision{1.6}
providecommandIssueDate{1999-Apr-09}
providecommandIssuedBy{AAG}
providecommandEffective{2009-Jun-30}
providecommandApprovedBy{The Supreme Approver}
providecommandApprovalDate{2016-11-12}

% the header and footer
setlengtharrayrulewidth{1pt}
newcommandHeadStrut{vrule height 2em depth 1.5em width 0pt}
pagestyle{fancy}
fancyhf{}
%This is to draw a rectangle as border
renewcommandheadrule{} % disable header rule
fancyhead[C]{%
  begin{tabular}{|m{0.60textwidth}|m{0.35textwidth}|}hline
    multicolumn{2}{|c|}{bfserieslarge Photometry and Radiometry Calibration DocumentHeadStrut}
    hline
    begin{tabular}{lm{75mm}}
         bfseriesUnit & 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.5textwidth}|m{0.2textwidth}|m{0.2textwidth}|}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.

providecommandUnit{PAR-117}
providecommandDescription{Spectral Irradiance Standards:newline Operating procedurenewline(A33-06-04-01 to A33-06-04-04)}
providecommandRevision{1.6}
providecommandIssueDate{1999-Apr-09}
providecommandIssuedBy{AAG}
providecommandEffective{2009-Jun-30}
providecommandApprovedBy{The Supreme Approver}
providecommandApprovalDate{2016-11-12}

Answered by user30471 on January 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP