计算 longtabu 的列宽并在使用多列时保留格式

计算 longtabu 的列宽并在使用多列时保留格式

我正在使用longtabu环境创建一个表格,总体外观几乎符合我的要求,但是我遇到了一些格式混乱的问题。以下是我想要做的:

在此处输入图片描述

如您所见,左侧和右侧的单元格multicolumn不再垂直居中,我不知道如何修复它。我以前makecell在表格中使用时遇到过类似的问题,我可以通过确保所有列都具有m正确对齐的属性来解决。但这似乎在这里不起作用。

此外,我希望能够动态计算四个组合列的宽度,而不必手动测量宽度,但我对 Latex 还不太熟悉,所以任何帮助都欢迎!以下是我到目前为止实现这一目标的方法,可能是我犯了一些不必要的错误,对 tex 还不太熟悉...

\begin{longtabu} to \textwidth 
{@{}|X[-1,l,m]
|X[-1,l,m]
|X[l,m]
|X[-1,l,m]|
X[-1,l,m]|
X[-1,l,m]|
X[l,m]|>{\color{gray}}X[-1,c,m]| @{}} 
\tabucline[1pt]-
\everyrow{\tabucline[0.5pt]-}
\rowcolor{light-gray} Name & Options & 3 & 4 & 5 & 6 & Attributes & Ref\\ 
\tabucline[1pt]-
\endhead
Name goes here & available options & Description & . & . & . & . & . \\
& Description of Option & \multicolumn{4}{l|}{\rlap{\parbox[t]{6.8cm}
{Here is supposed to be a very long text that is shown across 
colums 3 to 6, combining 4 columns, however when combining columns 
here the cells left and right of this text are no longer vertically 
centered and I have to manually add the width of this box.}}} 
& more attributes & ... \\
& Desc. 2 & & & & & \makecell{centered\\attributes\\seem to\\work here} &...\\
\end{longtabu}

答案1

这是使用包的表格,xltabular而不是longtabu已经推荐的Zarko 在评论中

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
\usepackage[table]{xcolor}
\definecolor{light-gray}{RGB}{130,130,130}
\usepackage{xltabular}
\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{document}

\begin{xltabular}{\textwidth}{|l|>{\raggedright\arraybackslash}X|l|l|l|l|>{\raggedright\arraybackslash}X|l|}
\hline
\rowcolor{light-gray} Name & Options & 3 & 4 & 5 & 6 & Attributes & \\ \hline
Name goes here & available options & Description & . & . & . & . & . \\ 
\hline
& Description of Option & \multicolumn{4}{m{5cm}|}{{Here is supposed to be a very long text that is shown across colums 3 to 6, combining 4 columns, however when combining columns here the cells left and right of this text are no longer vertically centered and I have to manually add the width of this box.}} 
& more attributes & ... \\
\hline
& Desc. 2 & & & & & centered attributes seem to work here &...\\
\hline
\end{xltabular}

\end{document}

相关内容