有没有办法模仿这个 MWE,但使用长表方法?
\documentclass{article}
\usepackage{table, tabular}
\begin{table}[!htbp]
\setlength\tabcolsep{.25cm}
\renewcommand{\arraystretch}{1}
\caption{Parameter description\strut}
\centering
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} ll@{}}
\toprule
\multicolumn{1}{@{}l}{{\color{blue} \textsc{Parameter}}} & \multicolumn{1}{l}{{\color{blue} \textsc{Description}}} \\
\midrule
\bottomrule
\end{tabular*}
\end{table}
\end{document}
答案1
- 目前并不完全清楚长表应该是什么样子...
- 另外,您没有给出任何有关餐桌内容的提示。
- 无需对第一行和第一列的类型进行着色,就像您在
tabular
表中所做的那样:
\documentclass{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum} % for dummy text
%---------------------------------------------------------------%
\usepackage{booktabs, longtable}
\begin{document}
\lipsum[1-4]
\begingroup
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\begin{longtable}{ @{\extracolsep{\fill}} ll @{} }
%
\caption{Parameter description}
\label{tab: ???} \\
\toprule
\textsc{Parameter} & \textsc{Description} \\
\midrule
\endfirsthead
\caption[]{Parameter description (continue)} \\
\toprule
\textsc{Parameter} & \textsc{Description} \\
\midrule
\endhead
\midrule
\multicolumn{2}{r}{\footnotesize\textit{Continued on the next page}}
\endfoot
\bottomrule
\endlastfoot
%
some text & some longer text \\
some long long
long text & some text \\
some text & some long long
long long text \\
long text & some text \\
some text & some long long
long long text \\
long text & some text \\
\end{longtable}
\endgroup
\lipsum[6-7]
\end{document}
但是,从表格标题可以得出结论,您的表格可能具有较窄的列,其中包含一些数学模式中的变量,而第二列则较宽,包含描述,即:它可能如下所示:
这可以通过使用以下xltabular
包获得:
\documentclass{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum} % for dummy text
%---------------------------------------------------------------%
\usepackage{booktabs, xltabular}
\begin{document}
\lipsum[1-4]
\noindent%
\begin{xltabular}{\linewidth}{ @{} >{$}l<{$} X @{} }
%
\caption{Parameter description}
\label{tab: ???} \\
\toprule
\textsc{Parameter} & \textsc{Description} \\
\midrule
\endfirsthead
\caption[]{Parameter description (continue)} \\
\toprule
\textsc{Parameter} & \textsc{Description} \\
\midrule
\endhead
\midrule
\multicolumn{2}{r}{\footnotesize\textit{Continued on the next page}}
\endfoot
\bottomrule
\endlastfoot
%
x & some longer text \\
y & some text \\
z & \lipsum[66] \\
\alpha & some text \\
\beta & some long teyt \\
\gamma & some text \\
\end{xltabular}
\lipsum[6-7]
\end{document}
附录:
更短的代码,也可以对表格中的第一行进行简单的着色,您可以使用包来制作tabularray
(在下面的 MWE 中使用版本 2022C):
\documentclass{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum} % for dummy text
%---------------------------------------------------------------%
\usepackage{colortbl}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\lipsum[1-4]
\noindent%
\begin{longtblr}[
caption = {Parameter description},
label = {tab: ???},
]{colspec = { @{} Q[l, mode=math] X[l] @{} },
row{1} = {font=\scshape, mode=text, bg=blue!30},
rowhead = 1
}
\toprule
Parameter & Description \\
\midrule
x & some longer text \\
y & some text \\
z & \lipsum[66] \\
\alpha & some text \\
\beta & some long teyt \\
\gamma & some text \\
\bottomrule
\end{longtblr}
\lipsum[6-7]
\end{document}
(上图中的红线表示页面布局)
答案2
我建议longtblr
这可能是最简单的解决方案(参见@Zarko 的回答)。
如果您无法将其添加到项目中,则xltabular
由于其X
列类型,这是一个选项,它在这种表格中有一个完美的用例,其中一个小列用于数字、符号,另一个用于描述。X
表示计算列的剩余空间,这里用于描述,或者如果有多个X
,它会将可用空间均匀地分配到多个列上。请注意,在环境X
中也可用。longtblr
使用 的完整示例。请注意、和xltabular
的用法,它们指定在第一页和每隔一页上应显示什么内容以及在何处显示。\endfirsthead
\endhead
\endfoot
\endlastfoot
编辑。如果您喜欢两端对齐的文本,请>{\RaggedRight\arraybackslash}
从行中删除该部分
>{\RaggedRight\arraybackslash}X
\documentclass{article}
\usepackage{geometry} % For a customised document layout
\usepackage{colortbl} % Adds colo(u)rs to tables
\usepackage{booktabs}
\usepackage{caption} % Improved captions
\captionsetup[table]{skip=6pt, format=hang, position=above}
\usepackage{xltabular} % A long table with X column-type
\usepackage{microtype} % These both packages are added for improved
\usepackage{ragged2e} % typeset in narrow environments
%%% Added only for dummy texts and can be removed
\usepackage{kantlipsum}
\usepackage{lipsum}
%%% END
\NewExpandableDocumentCommand\ctitle{O{l}m}{%
\multicolumn{1}{@{}#1}{\textcolor{blue}{\textsc{#2}}}}
\begin{document}
\kant[50]
\bgroup
\kantdef{\longcaptiontitle}{100}[1]
\setlength\tabcolsep{3pt}
\setlength{\LTcapwidth}{0.7\linewidth}
% \renewcommand{\arraystretch}{1.0}
\begin{xltabular}{0.8\linewidth}{
@{}
>{\centering\arraybackslash\(}p{2cm}<{\)}
>{\RaggedRight\arraybackslash}X % remove >{...} to keep text justified
@{}
}
% The very first heading
\caption{\longcaptiontitle} \\
\toprule\ctitle{Parameter} & \ctitle[c]{Description} \\
\midrule \endfirsthead
% Other heading on consecutive pages
\caption{\longcaptiontitle{} (\textit{Continued)}} \\
\toprule\ctitle{Parameter} & \ctitle[c]{Description} \\
\midrule \endhead
% Annotation under the table on consecutive pages
\bottomrule \addlinespace[2pt]
\multicolumn{2}{r@{}}{\textit{Continues on the next page \dots}} \endfoot
% Annotation on the row below the table
\bottomrule \endlastfoot
\alpha & \kant*[1][1] \\
\beta & \kant*[2][1] \\
\gamma & \kant*[3][1] \\
\delta & \kant*[4][1] \\
\varepsilon & \kant*[5][1] \\
\eta & \kant*[6][1] \\
\theta & \kant*[7][1] \\
\omega & \kant*[8][1] \\
\alpha & \kant*[1][1] \\
\beta & \kant*[2][1] \\
\gamma & \kant*[3][1] \\
\delta & \kant*[4][1] \\
\end{xltabular}
\egroup
\kant[51][1-3]
\end{document}