3

I would like to wrap the table in an environment, so that the table in-cell margins are reset and/or I have control over them.

It seems fancyhr is making this impossible to do, with the following approaches: Column and row padding in tables

\documentclass[12pt,a4paper]{abntex2} % Use A4 paper with a 12pt font size - different paper sizes will require manual recalculation of page margins and border positions

\usepackage[utf8]{inputenc} \usepackage{fancyhdr} % Required for header and footer configuration \usepackage[math]{cellspace} \usepackage{lipsum} \fancyhf{} % Clear default headers and footers \renewcommand{\headrulewidth}{0pt} \addtolength{\topmargin}{-4mm} \addtolength{\bottommargin}{+2mm} \addtolength{\footskip}{30mm} \addtolength{\textheight}{-20mm} \addtolength{\headsep}{+10mm} \usepackage{fancyhdr} % Required for header and footer configuration %%%%%%%%%%%% ----------- PACOTES/PACKAGES ----------- %%%%%%%%%%%%%% \usepackage{marginnote} % Required for margin notes \usepackage{wallpaper} % Required to set each page to have a background \usepackage{lastpage} % Required to print the total number of pages % \usepackage[left=1.3cm,right=2.0cm,top=1.8cm,bottom=5.0cm,marginparwidth=3.4cm]{geometry} % Adjust page margins \usepackage{amsmath} % Required for equation customization \usepackage{amssymb} % Required to include mathematical symbols \usepackage{xcolor} % Required to specify colors by name \usepackage{lipsum} \usepackage[T1]{fontenc} \usepackage{lmodern}

%%%%%%%%%%%% ----------- PACOTES/PACKAGES ----------- %%%%%%%%%%%%%%

%%%%%%%% ---------- ALGUM PROBLEMA -------- \usepackage{pstricks} % \usepackage{subfigure} %%%%%%%% Incompatibilidade/Incompatibility \usepackage{caption} % legendas nas figuras \captionsetup{justification=centering,labelfont=bf} \usepackage{textcomp} %%%%%%%% ---------- ALGUM PROBLEMA ---------

\usepackage{url} \usepackage{comment} % \usepackage[svgnames]{xcolor} \ifpdf \usepackage{pdfcolmk} \fi \usepackage{graphicx} \usepackage{hyperref} % \usepackage[outline]{contour} \usepackage{tikz} \usepackage{pifont} \ifxetex \usepackage{fontspec} \fi

\usepackage[hmargin=1cm,top=4cm,headheight=50pt,footskip=5pt]{geometry} \newenvironment{header-title}{\vspace{0pt}\center\bfseries\fontsize{7}{2}\selectfont\rmfamily \cellspacetoplimit 2pt \addtolength{\topmargin}{-5mm}}{} \newenvironment{footer-title}{\flushleft\bfseries\fontsize{8.5}{3}\selectfont\rmfamily}{}

\fancyhead[ce,co,le,lo,re,ro]{} %% clear out all headers \bgroup \def\arraystretch{} \fancyhead[c]{% % 1 is the default, change whatever you need \begin{tabular}{|m{3.0cm}|m{8cm}|m{2.5cm}|} \hline \begin{center} \includegraphics[height=1.5cm,width=3cm]{logo.png} \end{center} & \begin{header-title} Laudo Técnico de Apreciação de Riscos e \newline Análise de Conformidade Legal Máquina NR-12 \newline Segurança no Trabalho em Máquinas e Equipamentoso. \end{header-title} & \centering \tiny{Página \thepage\ de \pageref{LastPage}\ data: 10/04/2021\ } \[10mm] \tabularnewline \hline \end{tabular}% \egroup }

\fancyfoot[ce,co,le,lo,re,ro]{} %% clear out all headers \fancyfoot[c]{% \begin{tabular}{|m{3cm}|m{8cm}|m{2.5cm}|} \hline \begin{center} \includegraphics[height=1cm,width=4cm]{logo.png} \end{center} & % \centering % \begin{tabular}{c} \begin{footer-title} Elaborado por: Wagner José Branquinho, \newline Engenheiro Mecânico e de Segurança do Trabalho. \newline \begin{center} CREA 0601546708 \end{center} \end{footer-title} % \end{tabular} & \centering \tiny{Página \thepage\ de \pageref{LastPage}\ data: 14/10/2020\ rev. 0}\tabularnewline \hline \end{tabular}% }

\begin{document}

\pagestyle{fancy}

\section{Secção 1} \lipsum[1] % \AddToShipoutPicture{\BackgroundStructure} % Set the background of %each page to that specified above in the header information section % \pagebreak \section{Secção2} \lipsum[3]

\section{Título parte} \lipsum[4]

\section{Secção 1} \lipsum[1] % \AddToShipoutPicture{\BackgroundStructure} % Set the background of %each page to that specified above in the header information section % \pagebreak \section{Secção2} \lipsum[3]

\section{Título parte} \lipsum[4] \end{document}

I would like to make this highlighted text to close on the top of the cell. what I experience:

Very close reproduction can be found here: https://www.overleaf.com/6525723987nfydcfgtqyrg

Simon Dispa
  • 39,141
BuddhiLW
  • 177
  • 2
    welcome to the site -- your link does not work -- the code should be self contained so that it can be compiled to show the problem -- if the desire is to only have a fancyhdr would another solution be okay or is it only with a tabular environ – js bibra Apr 11 '21 at 00:29
  • 1
    Which \documentclass you use, where is defined {header-title}, what is the problem? Please provide MWE (Minimal Working Example), a small but complete document which reproduce your problem. – Zarko Apr 11 '21 at 02:57
  • I changed the Overleaf link. I had just copied the link at first. Now, I turned "sharing on". Sorry for that.

    The document class I use is abntex2; but i'm pretty sure it has nothing to do with it. Because it an norm-specific to Brazilian technical documents and their table is very different, when you use their examples/ambients for writing them.

    I would like to have a table inside my header and footer. If it didn't use fancyhdr, I would totally be satisfied with this other solution

    – BuddhiLW Apr 11 '21 at 15:03
  • 1
    Please. provide MWE in your question. After while link can be dead. – Zarko Apr 11 '21 at 15:42
  • Done. I copied the content of the link – BuddhiLW Apr 11 '21 at 18:14

1 Answers1

4

These headings provide a good approximation of your goal, with a control of the cell margins.

Both the header and footer were made with a table: a single row by three columns wide

The package fancyhdr was combined with nicematrix for the table.

The latter provides the \Block command which makes the code more compact, easier to read, and easier to maintain. (There is just one new command to learn!) Most importantly, it also allows you to use \\ to start a new line.

The single directive hvlines creates all the vertical and horizontal lines. The cells can be expanded vertically with cell-space-...

a

This is the code. For clarity, I left in the preamble only the packages needed to run the code.

You can choose to display this style only on the first page of your document or on all of them (using \pagestyle {firstpagestyle}).

% !TeX TS-program = pdflatex

\documentclass[12pt,a4paper]{abntex2} % Use A4 paper with a 12pt font size - different paper sizes will require manual recalculation of page margins and border positions

%%%%%%%%%%%% ----------- PACOTES/PACKAGES ----------- %%%%%%%%%%%%%% \usepackage[hmargin=1cm,top=4cm,headheight=50pt,footskip=5pt]{geometry} \addtolength{\topmargin}{-4mm} \addtolength{\footskip}{30mm} \addtolength{\textheight}{-20mm} \addtolength{\headsep}{+10mm}

\usepackage[utf8]{inputenc} \usepackage{lastpage} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{lipsum} \usepackage{graphicx}

%%%%%% HEADERS <<<<<<<<<<<<<< \usepackage{nicematrix} % <<<< added for an easy table \usepackage[datesep=/,useregional=numeric]{datetime2} %<<<<< added format date \DTMsetdatestyle{ddmmyyyy}

\usepackage{fancyhdr} % Required for header and footer configuration \renewcommand{\headrulewidth}{0pt}

\fancypagestyle{firstpagestyle}{% to use only in the first page \fancyhf{}% Clear default headers and footers \fancyhead[C]{% \begin{NiceTabular}{ccc}[hvlines, cell-space-top-limit=6pt,cell-space-bottom-limit=1pt] \Block{}{\includegraphics[height=1.5cm,width=3cm]{example-grid-100x100pt}}& \Block[l]{}<\bfseries\fontsize{8.5}{12}\selectfont >{Laudo Técnico de Apreciação de Riscos e \ Análise de Conformidade Legal Máquina NR-12 \Segurança no Trabalho em Máquinas e Equipamentoso.}& \Block{}<\tiny> {Página\ \thepage\ de\ \pageref{LastPage} \ data: \DTMToday} \ \end{NiceTabular}%
} % end fancy head \fancyfoot[C]{%
\begin{NiceTabular}{ccc}[hvlines, cell-space-top-limit=6pt,cell-space-bottom-limit=1pt] \Block{}{\includegraphics[height=1.5cm,width=3cm]{example-grid-100x100pt}}& \Block[l]{}<\bfseries\fontsize{8.5}{12}\selectfont>{Elaborado por: Wagner José Branquinho, \ Engenheiro Mecânico e de Segurança do Trabalho. \ \hspace{\fill} CREA 0601546708\hspace{\fill}} & \Block{}<\tiny> {Página\ \thepage\ de\ \pageref{LastPage} \ data: 10/4/2020 \ rev. 0} \ \end{NiceTabular}% end fancy foot }
}%%%%%% firstpagestyle ends

\begin{document}

% \pagestyle{firstpagestyle} % repeat on all pages <<<<<<<<<<<<<<<

\thispagestyle{firstpagestyle} % or only the first page <<<<<<<<<<<<<<

\section{Secção 1} \lipsum[1] % \AddToShipoutPicture{\BackgroundStructure} % Set the background of %each page to that specified above in the header information section % \pagebreak \section{Secção2} \lipsum[3]

\section{Título parte} \lipsum[4]

\section{Secção 1} \lipsum[1] % \AddToShipoutPicture{\BackgroundStructure} % Set the background of %each page to that specified above in the header information section % \pagebreak \section{Secção2} \lipsum[3]

\section{Título parte} \lipsum[4] \end{document}

Simon Dispa
  • 39,141
  • Great. That was indeed a great solution. I ended up using some pretty complicated solution - fitbox setup (https://tex.stackexchange.com/questions/26002/fit-text-into-given-box-by-adjusting-the-fontsize#26006); combined with table manual scaling. So, my workaround works in a very especial case, only. If I change the text, this get screwed pretty fast.

    Thank you!

    – BuddhiLW Apr 11 '21 at 23:53
  • +1 a very nice answer – js bibra Apr 12 '21 at 00:26