这可能与这个问题类似:如何使标题中的表格忽略当前处理的长表设置的环境
我真的没能从中得到答案。我的 fancyhdr 中有一个表格环境,它运行良好,但是当我在 longtable 之前执行 arraystretch 或 extrarowheight 时,标题也会被拉伸,而这并不是我想要的。我尝试过对 longtable 进行分组,但似乎没有任何效果。如果需要,我将提供更多代码。
我有一张长桌:
\begingroup
\setlength{\extrarowheight}{0.5cm}
\begin{longtable}{|C{1cm} | L{3cm} | L{12.6cm}|}
%CONTENT
\end{longtable}
\endgroup
以下是 usepackages 和其他配置
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[12pt, twoside, a4paper]{article} % Use A4 paper with a 12pt font size - different paper sizes will require manual recalculation of page margins and border positions
\usepackage[utf8]{inputenc}% latin1 utf8
\usepackage[T1]{fontenc}
\usepackage{amsmath} % Required for equation customization
\usepackage{amssymb} % Required to include mathematical symbols
\usepackage{xcolor} % Required to specify colors by name
\usepackage[norsk]{babel}
\usepackage{tabularx} %Adds the X possibility to tabular
\usepackage{longtable}
\usepackage{ltxtable}
\usepackage{booktabs}
\usepackage{lastpage} % Required to print the total number of pages
\usepackage{graphicx}
\usepackage{varioref}
\usepackage{multirow}
\usepackage{array}
\usepackage{enumerate}
\usepackage{fancyhdr} % Required to customize headers
\usepackage[pagebackref=false]{hyperref}
\usepackage{color}
\usepackage{appendix}
\usepackage{nomencl}
\usepackage{verbatim}
\usepackage{cleveref}
\usepackage{grffile}
\usepackage{pdfpages}
\usepackage[left=1.5cm,right=1.5cm,top=5cm,bottom=4.0cm,marginparwidth=0pt, headheight=2.5cm ]{geometry} % Adjust page margins
%\usepackage{showframe} % Show margins on page
\pagestyle{fancy}\fancyhf{} % Use the custom header specified below
\renewcommand{\headrulewidth}{0pt} % Remove the default horizontal rule under the header
\setlength{\parindent}{0cm} % Remove paragraph indentation
\newcommand{\tab}{\hspace*{2em}} % Defines a new command for some horizontal space
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\tolerance = 5000 %3000
\hbadness = \tolerance
\pretolerance = 2000 %1000
\input{./Header/Header}
\begin{document}
\def\contentsname{Innholdsfortegnelse} %Dette blir navnet i Innholdsfortegnelsen
\tableofcontents
\newpage
%----------------------------------------------------------------------------------------
% REVISJONSHISTORIKK
%----------------------------------------------------------------------------------------
\input{./Revisjonshistorikk/Revisjonshistorikk} % THE LONGTABLE IS PLACE IN HERE
\end{document}
\renewcommand\arraystretch{1.0}
这是之前的结果longtable
。
\renewcommand\arraystretch{1.5}
这是之前的结果longtable
。
答案1
我使用了一些虚拟的东西来替换您的内容,我们都没有。以下使用我在评论中提出的方法。即我将setlength\extrarowheight{0pt}
或\def\arraystretch{1}
明确地放在 -group 内的标题中\bgroup...\egroup
。这样,指定的额外空间longtable
不会影响标题。
使用\extrarowheight
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[12pt, twoside, a4paper]{article} % Use A4 paper with a 12pt font size - different paper sizes will require manual recalculation of page margins and border positions
\usepackage[utf8]{inputenc}% latin1 utf8
\usepackage[T1]{fontenc}
\usepackage{amsmath} % Required for equation customization
\usepackage{amssymb} % Required to include mathematical symbols
\usepackage{xcolor} % Required to specify colors by name
\usepackage[norsk]{babel}
\usepackage{tabularx} %Adds the X possibility to tabular
\usepackage{longtable}
\usepackage{ltxtable}
\usepackage{booktabs}
\usepackage{lastpage} % Required to print the total number of pages
\usepackage{graphicx}
\usepackage{varioref}
\usepackage{multirow}
\usepackage{array}
\usepackage{enumerate}
\usepackage{fancyhdr} % Required to customize headers
\usepackage[pagebackref=false]{hyperref}
\usepackage{color}
\usepackage{appendix}
\usepackage{nomencl}
\usepackage{verbatim}
\usepackage{cleveref}
\usepackage{grffile}
\usepackage{pdfpages}
\usepackage[left=1.5cm,right=1.5cm,top=5cm,bottom=4.0cm,marginparwidth=0pt, headheight=2.5cm ]{geometry} % Adjust page margins
%\usepackage{showframe} % Show margins on page
\pagestyle{fancy}\fancyhf{} % Use the custom header specified below
\renewcommand{\headrulewidth}{0pt} % Remove the default horizontal rule under the header
\setlength{\parindent}{0cm} % Remove paragraph indentation
\newcommand{\tab}{\hspace*{2em}} % Defines a new command for some horizontal space
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\tolerance = 5000 %3000
\hbadness = \tolerance
\pretolerance = 2000 %1000
%\input{./Header/Header}
\lhead{%
\bgroup
\setlength\extrarowheight{0pt}%
\begin{tabular}{lcl}
\hline
This & is & my\\
awesome&looking&header\\
\hline
\end{tabular}%
\egroup}
\begin{document}
\def\contentsname{Innholdsfortegnelse} %Dette blir navnet i Innholdsfortegnelsen
\tableofcontents
\newpage
%----------------------------------------------------------------------------------------
% REVISJONSHISTORIKK
%----------------------------------------------------------------------------------------
%\input{./Revisjonshistorikk/Revisjonshistorikk} % THE LONGTABLE IS PLACE IN HERE
\begingroup
\setlength{\extrarowheight}{0.5cm}
\begin{longtable}{|C{1cm} | L{3cm} | L{12.6cm}|}
\hline
this & is & some\\
\hline
dummy & content& just\\
to & see & the\\
table&formatting&of\\
this&&\\
\hline
\end{longtable}
\endgroup
\end{document}
使用\def\arraystretch{2}
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\documentclass[12pt, twoside, a4paper]{article} % Use A4 paper with a 12pt font size - different paper sizes will require manual recalculation of page margins and border positions
\usepackage[utf8]{inputenc}% latin1 utf8
\usepackage[T1]{fontenc}
\usepackage{amsmath} % Required for equation customization
\usepackage{amssymb} % Required to include mathematical symbols
\usepackage{xcolor} % Required to specify colors by name
\usepackage[norsk]{babel}
\usepackage{tabularx} %Adds the X possibility to tabular
\usepackage{longtable}
\usepackage{ltxtable}
\usepackage{booktabs}
\usepackage{lastpage} % Required to print the total number of pages
\usepackage{graphicx}
\usepackage{varioref}
\usepackage{multirow}
\usepackage{array}
\usepackage{enumerate}
\usepackage{fancyhdr} % Required to customize headers
\usepackage[pagebackref=false]{hyperref}
\usepackage{color}
\usepackage{appendix}
\usepackage{nomencl}
\usepackage{verbatim}
\usepackage{cleveref}
\usepackage{grffile}
\usepackage{pdfpages}
\usepackage[left=1.5cm,right=1.5cm,top=5cm,bottom=4.0cm,marginparwidth=0pt, headheight=2.5cm ]{geometry} % Adjust page margins
%\usepackage{showframe} % Show margins on page
\pagestyle{fancy}\fancyhf{} % Use the custom header specified below
\renewcommand{\headrulewidth}{0pt} % Remove the default horizontal rule under the header
\setlength{\parindent}{0cm} % Remove paragraph indentation
\newcommand{\tab}{\hspace*{2em}} % Defines a new command for some horizontal space
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\tolerance = 5000 %3000
\hbadness = \tolerance
\pretolerance = 2000 %1000
%\input{./Header/Header}
\lhead{%
\bgroup
\def\arraystretch{1}%
\begin{tabular}{lcl}
\hline
This & is & my\\
awesome&looking&header\\
\hline
\end{tabular}%
\egroup}
\begin{document}
\def\contentsname{Innholdsfortegnelse} %Dette blir navnet i Innholdsfortegnelsen
\tableofcontents
\newpage
%----------------------------------------------------------------------------------------
% REVISJONSHISTORIKK
%----------------------------------------------------------------------------------------
%\input{./Revisjonshistorikk/Revisjonshistorikk} % THE LONGTABLE IS PLACE IN HERE
\begingroup
\def\arraystretch{2}%
\begin{longtable}{|C{1cm} | L{3cm} | L{12.6cm}|}
\hline
this & is & some\\
\hline
dummy & content& just\\
to & see & the\\
table&formatting&of\\
this&&\\
\hline
\end{longtable}
\endgroup
\end{document}
答案2
比使用更好的方法\arraystretch
是在单元格内容之前和之后添加垂直空间。这种可能性提供了makcell
包。不幸的是\makegapedcells
,执行此操作的宏与“m{...}˙column 类型”不兼容。然而,乌尔丽克·菲舍尔为此提供补丁。
A姆韦(为此,我从您的文档序言中删除了所有不必要的包):
\documentclass[12pt, twoside, a4paper]{article}
\usepackage{array, booktabs, longtable}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\usepackage{makecell}% <-- added
\makeatletter % <-- patch for m columns
\renewcommand\mcell@classz{\@classx
\@tempcnta \count@
\prepnext@tok
\@addtopreamble{%\mcell@mstyle
\ifcase\@chnum
\hfil
\mcell@agape{\d@llarbegin\insert@column\d@llarend}\hfil \or
\hskip1sp
\mcell@agape{\d@llarbegin\insert@column\d@llarend}\hfil \or
\hfil\hskip1sp
\mcell@agape{\d@llarbegin \insert@column\d@llarend}\or
\mcell@agape{$\vcenter
\@startpbox{\@nextchar}\insert@column\@endpbox$}\or
\mcell@agape{\vtop
\@startpbox{\@nextchar}\insert@column\@endpbox}\or
\mcell@agape{\vbox
\@startpbox{\@nextchar}\insert@column\@endpbox}%
\fi
\global\let\mcell@left\relax\global\let\mcell@right\relax
}\prepnext@tok}
\makeatother
\setcellgapes{7pt}
\usepackage{lipsum} % for dummy text
\begin{document}
\begin{longtable}{|C{1cm} | L{3cm} | L{12.6cm}|}
\hline
1 & some text & \lipsum*[11]\\
\hline
2 & some text & \lipsum*[11]\\
\hline
\end{longtable}
\begingroup
\makegapedcells
\begin{longtable}{|C{1cm} | L{3cm} | L{12.6cm}|}
\hline
1 & some text & \lipsum*[11]\\
\hline
2 & some text & \lipsum*[11]\\
\hline
\end{longtable}
\endgroup
\end{document}
补充: 然而,我会以不同的方式设计这张表
\documentclass[12pt,twoside,a4paper]{article}
\usepackage{booktabs, longtable}
\usepackage{lipsum} % for dummy text
%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{longtable}{p{1cm} p{2cm} p{\dimexpr\linewidth-3cm-6\tabcolsep}}
\toprule
A & B & C \\
\midrule
1 & some text & \lipsum*[11] \\
\addlinespace
2 & some text & \lipsum*[11] \\
\bottomrule
\end{longtable}
\end{document}