如何使用 tabularx 控制 longtable 中多列的宽度

如何使用 tabularx 控制 longtable 中多列的宽度

我有以下表格,该表格延伸到多页。有人能帮我弄清楚如何控制列宽,以便第二列和第三列具有最大宽度,而其他三列具有最小宽度,并且文本居中对齐吗?

我尝试了在线发布的解决方案,但我的文本格式不正确或表格不适合页面宽度。

\documentclass{article}

\usepackage{xltabular}

\title{A longtable + tabularx example, using xltabular}

\begin{document}

\begin{xltabular}{\textwidth}{|c|X|X|X|X|}
\caption{Planning overview} \label{tab:long} \\

\hline \multicolumn{1}{|c|}{\textbf{Sl. No}} & \multicolumn{1}{c|}{\textbf{Research Question}} & \multicolumn{1}{c|}{\textbf{Corresponding Experiment}} & \multicolumn{1}{c|}{\textbf{No of weeks}}& \multicolumn{1}{c|}{\textbf{Timeframe}}\\ \hline 
\endfirsthead

\multicolumn{3}{c}%
{\tablename\ \thetable{} -- continued from previous page} \\
\hline \multicolumn{1}{|c|}{\textbf{Sl. No}} & \multicolumn{1}{c|}{\textbf{Research Question}} & \multicolumn{1}{c|}{\textbf{Corresponding Experiment}} & \multicolumn{1}{c|}{\textbf{No of weeks}}& \multicolumn{1}{c|}{\textbf{Timeframe}}\\ \hline 
\endhead

\hline \multicolumn{5}{|r|}{{Continued on next page}} \\ \hline
\endfoot

\hline
\endlastfoot

One & abcdef ghjijklmn & 123.456778 & 1 &  7 Jun - 25 Jun
(parallely with step 4 and 5)\\


\end{xltabular}

\end{document}

图像如下所示: 当前图像

答案1

以下可能更接近预期的输出?

在此处输入图片描述

\documentclass{article}
\usepackage{makecell,calc}
\renewcommand{\theadfont}{\bfseries}
\usepackage{xltabular}

\title{A longtable + tabularx example, using xltabular}

\begin{document}

\begin{xltabular}{\textwidth}{|c|X|X|c|>{\centering\arraybackslash}p{2cm}|}
\caption{Planning overview} \label{tab:long} \\

\hline \thead{Sl. No} & \thead{Research\\ Question} & \thead{Corresponding\\ Experiment} & \thead{No of\\ weeks}&\thead{Timeframe}\\ \hline 
\endfirsthead

\caption[]{Planning overview -- continued from previous page} \\
\hline \thead{Sl. No} & \thead{Research\\ Question} & \thead{Corresponding\\ Experiment} & \thead{No of\\ weeks}&\thead{Timeframe}\\ \hline 
\endhead

\hline \multicolumn{5}{|r|}{{Continued on next page}} \\ \hline
\endfoot

\hline
\endlastfoot

One & abcdef ghjijklmn & 123.456778 & 1 &  7 Jun - 25 Jun
(parallely with step 4 and 5)\\


\end{xltabular}

\end{document}

相关内容