LaTeX:多页表格,单元格内容居中,并适应列宽

LaTeX:多页表格,单元格内容居中,并适应列宽

我正在使用 Overleaf,需要创建一个多页表(longtable),由以下部分组成:n行 3 列,具有以下特点:

  1. 表格宽度适应页面宽度(列宽);
  2. 第一列和第二列的单元格内容垂直和水平居中;
  3. 第三列单元格的文本换行。

下面是一个示例,可以更好地解释我想要获取的格式类型:

在此处输入图片描述

我曾尝试过这些软件包,但这些特性都不太好用:

  • \begin{longtabu} to \columnwidth {|c|c|X|}没有解决第 2 点并产生了可怕的行距;
  • \begin{tabularx}{\columnwidth}{|c|c|X|}\renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}}序言中(垂直居中单元格内容)工作正常,但不会返回多页表。

你有什么建议?提前谢谢。

答案1

您可以使用xltabular自动适应文本宽度并可跨越多页的表格。但请注意,分页符只能出现在表格行之间,而不能出现在表格行内。

在此处输入图片描述

\documentclass{article}
\usepackage{xltabular}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\usepackage[x11names,table]{xcolor}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}

\usepackage{lipsum}
\begin{document}
\begin{xltabular}{\textwidth}{|>{\ttfamily}l|l|X|}
\caption{a caption text} \label{key}\\
\hline
\rowcolor{DarkSeaGreen1}\thead{text} & \thead{text} & \thead{longer text}\\
\hline
\endhead
text & text & \lipsum[4] \\
\hline
text & text & \lipsum[4] \\
\hline
text & text & \lipsum[4] \\
\hline
text & text & \lipsum[4] \\
\hline
text & text & \lipsum[4] \\
\hline
\end{xltabular}
\end{document}

相关内容