我正在尝试设置一个 tabularx 表,其中第一列有非常长的项目描述
\documentclass[12pt,ngerman]{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{table}[!htb]
\begin{tabularx}{\textwidth}{lccc}\toprule
Item & MW & SD & span\\\midrule
This is a very very very very very very very very very very very very very very very very long item description. & $2.58$ & $0.90$ & $1-4$ \\\bottomrule
\end{tabularx}
\end{table}
\end{document}
目前,编译效果很差,因为 LaTeX 允许第一列延伸到整个项目描述的长度。我该怎么做才能获得更好的结果,例如,我有 5 行文本,但列的宽度可以接受?
答案1
X
对第一列使用 columntype :
\begin{tabularx}{\textwidth}{Xccc}
是X
类型的列p
。如果要将其他列中的值垂直居中,则必须重新定义\tabularxcolumnn
为
\renewcommand\tabularxcolumn[1]{m{#1}}
代码:
\documentclass[12pt,ngerman]{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{booktabs}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\begin{table}[!htb]
\begin{tabularx}{\textwidth}{Xccc}\toprule
Item & MW & SD & span\\\midrule
This is a very very very very very very very very very very very very very very very very long item description. & $2.58$ & $0.90$ & $1-4$ \\\bottomrule
\end{tabularx}
\end{table}
\end{document}