我使用 创建了一个包含 3 列的特定表格\newenvironment
。现在我想在每行之间以及从第 2 列到第 3 列之间添加一条线。我知道可以\cmidrule{2-3}
在每行末尾添加,但我会在我创建的环境中编写一些内容以实现相同的结果,然后仅\\
在每行末尾添加。
您能建议我在声明环境期间添加一些命令吗?
编辑 1:问题有点复杂。这是我的环境:
\newenvironment{propRules}[2]{
\begin{longtable}{r{>{$\displaystyle}c<{$}}{>{$\displaystyle}l<{$}}}
\toprule
\multicolumn{2}{c}{\texttt{#1}} & \multicolumn{1}{c}{\texttt{#2}} \\
\midrule
\endfirsthead
\multicolumn{3}{l}{\footnotesize\itshape
Continue from previous page} \\
\toprule
\multicolumn{2}{c}{\texttt{#1}} & \multicolumn{1}{c}{\texttt{#2}} \\
\midrule
\endhead
\midrule
\multicolumn{3}{r}{\footnotesize\itshape
Continue in the following page} \\
\endfoot
\bottomrule
\endlastfoot
}
{\end{longtable}}
我想修改我的环境,使表格的行之间有一条线:特别是那条线必须只位于第二列和第三列之间。此外,由于该表格可以分成更多页面(longtable
),因此页面最后一行末尾的线不能显示,因为已经有了那条\midrule
线。
编辑 2:我解决了\newcommand\tncr{\tabularnewline\cmidrule{2-3}}
,但仍然存在页面最后一行末尾的行的问题:它不能显示,因为已经有 \midrule 行。
有什么建议么?
编辑3:这是MWE:
\documentclass[a4paper,10pt]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{longtable} % for table in more than one page
\usepackage{booktabs} % top, mid, bottom rule in tabular
\usepackage{array} % personalize column in tabular
\usepackage{multirow} % multirow, multicolumn in tabular
% column with math env in display style
\newcolumntype{L}{>{$\displaystyle}l<{$}}
\newcolumntype{C}{>{$\displaystyle}c<{$}}
\newcolumntype{R}{>{$\displaystyle}r<{$}}
%%% LONGTABLE DECLARATION %%%%%%%%%
\newenvironment{tablebig}[2]{
\setlength\LTleft{0pt} % to obtain {\textwidth}
\setlength\LTright{0pt} % to obtain {\textwidth}
\begin{longtable}{rCL}
\toprule
\multicolumn{2}{c}{\texttt{#1}} & \multicolumn{1}{c}{\texttt{#2}} \\
\midrule
\endfirsthead
% new page heading
\multicolumn{3}{l}{\footnotesize\itshape
Continue from previous page} \\
\toprule
\multicolumn{2}{c}{\texttt{#1}} & \multicolumn{1}{c}{\texttt{#2}} \\
\midrule
\endhead
% end page foot
\midrule
\multicolumn{3}{r}{\footnotesize\itshape
Continue in the following page} \\
\endfoot
% final foot
\bottomrule
% \multicolumn{3}{r}{\footnotesize\itshape
% Conclusion from previous page} \\
\endlastfoot
% corpo della tabella
}
{\end{longtable}}
\begin{document}
\title{MWE}
\maketitle
\section{Section}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
% line between rows
\newcommand\tncm{\tabularnewline\cmidrule{2-3}}
\begin{tablebig}{First Column}{Second Column}
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test
\end{tablebig}
\end{document}
如果你编译它,你会注意到在第一页的末尾有两行:一行由 产生\tncm
,一行由 产生\midrule
。在其他情况下,双线位于第二页的开头。如何解决这个问题?
答案1
您可以重新定义cmidrule
,以便分页符总是出现在之后\cmidrule
:
\makeatletter
\def\cmidrule{\noalign{\ifnum0=`}\fi
\penalty\@M%
\@ifnextchar[{\@cmidrule}{\@cmidrule[\cmidrulewidth]}}
\makeatother
现在你可以调整大卫·卡莱尔的解决方案:
% end page foot
\noalign{\vskip-\cmidrulesep}
\midrule
\multicolumn{3}{r}{\footnotesize\itshape
Continue in the following page} \\
\endfoot
以下是完整的 MWE:
\documentclass[a4paper,10pt]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{longtable} % for table in more than one page
\usepackage{booktabs} % top, mid, bottom rule in tabular
\usepackage{array} % personalize column in tabular
\usepackage{multirow} % multirow, multicolumn in tabular
\makeatletter
\def\cmidrule{\noalign{\ifnum0=`}\fi
\penalty\@M%
\@ifnextchar[{\@cmidrule}{\@cmidrule[\cmidrulewidth]}}
\makeatother
% column with math env in display style
\newcolumntype{L}{>{$\displaystyle}l<{$}}
\newcolumntype{C}{>{$\displaystyle}c<{$}}
\newcolumntype{R}{>{$\displaystyle}r<{$}}
%%% LONGTABLE DECLARATION %%%%%%%%%
\newenvironment{tablebig}[2]{
\setlength\LTleft{0pt} % to obtain {\textwidth}
\setlength\LTright{0pt} % to obtain {\textwidth}
\begin{longtable}{rCL}
\toprule
\multicolumn{2}{c}{\texttt{#1}} & \multicolumn{1}{c}{\texttt{#2}} \\
\midrule
\endfirsthead
% new page heading
\multicolumn{3}{l}{\footnotesize\itshape
Continue from previous page} \\
\toprule
\multicolumn{2}{c}{\texttt{#1}} & \multicolumn{1}{c}{\texttt{#2}} \\
\midrule
\endhead
% end page foot
\noalign{\vskip-\cmidrulesep}
\midrule
\multicolumn{3}{r}{\footnotesize\itshape
Continue in the following page} \\
\endfoot
% final foot
\bottomrule
% \multicolumn{3}{r}{\footnotesize\itshape
% Conclusion from previous page} \\
\endlastfoot
% corpo della tabella
}
{\end{longtable}}
\begin{document}
\title{MWE}
\maketitle
\section{Section}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
% line between rows
\newcommand\tncm{\tabularnewline\cmidrule{2-3}}
\begin{tablebig}{First Column}{Second Column}
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test \tncm
test & test & test
\end{tablebig}
\end{document}