格式化表格单元格顶部和底部边距

格式化表格单元格顶部和底部边距

我想在环境中包装表格,以便重置表格单元格边距和/或我可以控制它们。

看来 fancyhr 使这成为不可能的事情,它采用了以下方法: 表格中的列和行填充

\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}

我想让这个突出显示的文本关闭在单元格的顶部。 我的经历:

非常接近的复制品可以在这里找到: https://www.overleaf.com/6525723987nfydcfgtqyrg

答案1

这些标题可以很好地近似您的目标,并可以控制单元格边距。

页眉和页脚均由表格制成:一行,三列宽

该包与桌子fancyhdr组合在一起。nicematrix

后者提供的\Block命令使代码更紧凑、更易读、更易于维护。(只需学习一个新命令!)最重要的是,它还允许您使用\\开始新行。

单个指令hvlines创建所有垂直和水平线。可以使用以下命令垂直扩展单元格 cell-space-...

A

这是代码。为了清晰起见,我在序言中只保留了运行代码所需的包。

您可以选择仅在文档的第一页或所有页上显示此样式(使用\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}

相关内容