我对 Latex 还不是很熟悉。我用它tabularx
创建一个多行表格,还用它ltablex
来扩展到多个页面。下面的代码代表了我面临的问题,包含最大文本量的列应该扩展,并强制其余文本适应它,但实际上却被渲染为最窄!任何帮助都非常感谢。
\usepackage{ltablex}
\begin{tabularx}{\textwidth}{|l|X|l|l|l|}
\hline
& & \multicolumn{3}{c|}{\textbf{TEST}}\\\hline
\textbf{ID} & \textbf{CRITERIA} & \textbf{(A)} & \textbf{(B)} & \textbf{(C)} \\ \hline
\multicolumn{5}{|c|}{\cellcolor[HTML]{FFFFFF}{\color[HTML]{000000} \textbf{Category}}} \\ \hline
\#1 & Very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long text
& Not so long text & Bit longer text than was before, but still short & Usually empty \\ \hline
\end{tabularx}
我能得到的最接近的答案是:
begin{tabularx}{\textwidth}{|l|L|X|X|X|}
从哪里来。L
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
来源。此声明是否X
会引起此问题?
答案1
如果你有
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|l|X|l|l|l|}
\hline
& & \multicolumn{3}{c|}{\textbf{TEST}}\\\hline
\textbf{ID} & \textbf{CRITERIA} & \textbf{(A)} & \textbf{(B)} & \textbf{(C)} \\ \hline
\multicolumn{5}{|c|}{\cellcolor[HTML]{FFFFFF}{\color[HTML]{000000} \textbf{Category}}} \\ \hline
\#1 & Very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long text
& Not so long text & Bit longer text than was before, but still short & Usually empty \\ \hline
\end{tabularx}
\end{document}
然后您指定将 4 列设置为左对齐的单列单元格,其宽度为该列中最大条目的自然宽度。确定这些宽度后,TeX 将尝试\textwidth
通过调整列的宽度X
并允许在这些单元格内中断留置权来使表格的总宽度达到指定值。
你没有给出文本宽度的指示(或如何\cellcolor
定义),但假设一个标准文章,xcolor
然后上面的例子产生
您可以按照L
问题中的建议将 l 替换为,或者对于手写文档表(而不是自动数据库转储),通常最好手动选择列宽p{4cm}
或您想要的任何宽度,然后只需留下一列 X 来填充剩余空间(如果您希望表格占满整个宽度)。
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\begin{document}
\begin{center}
\setlength\extrarowheight{2pt}
\begin{tabularx}{\textwidth}{|l|X|>{\raggedright}p{2cm}|>{\raggedright}p{3cm}|l|}
\hline
& & \multicolumn{3}{|c|}{\textbf{TEST}}\\\hline
\textbf{ID} & \textbf{CRITERIA} & \textbf{(A)} & \textbf{(B)} & \textbf{(C)} \\ \hline
\multicolumn{5}{|c|}{\cellcolor[HTML]{FFFFFF}{\color[HTML]{000000} \textbf{Category}}} \\ \hline
\#1 & Very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long text
& Not so long text & Bit longer text than was before, but still short & Usually empty \\ \hline
\end{tabularx}
\end{center}
\end{document}