有没有办法将表格的单元格内容对齐到顶部?我正在使用一个 tabularx 表格,其中 X 列垂直居中,但我希望表格中的单个单元格顶部对齐。
当然,这里有一个 MWE:
\documentclass[BCOR=10mm,DIV=calc]{scrreprt}
\usepackage[english,ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{libertine}
\usepackage{booktabs}
\usepackage{ragged2e}
\usepackage{tabularx}
\usepackage{adjustbox}
\usepackage{ragged2e}
\renewcommand{\tabularxcolumn}[1]{>{}m{#1}}
\begin{document}
\begin{table}
\caption{Test}
\begin{adjustbox}{scale=0.7}
\scriptsize\sffamily
\begin{tabularx}{1.3\textwidth}{@{}>{\hspace{0pt}\centering\arraybackslash}m{1cm}>{\RaggedRight\arraybackslash}X>{\RaggedRight\arraybackslash}X>{\RaggedRight\arraybackslash}X>{\RaggedRight\arraybackslash}X>{\RaggedRight\arraybackslash}X@{}}
\toprule
\textbf{XYZ} & \centering\textbf{I want to be vertically aligned} & \centering\textbf{Me too} & \centering\textbf{And me too} & \centering\textbf{Same here} & \centering\textbf{And again}\tabularnewline
\midrule
5-6 & I WANT TO BE TOP ALIGNED, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua\\
\bottomrule
\end{tabularx}
\end{adjustbox}
\end{table}
\end{document}
答案1
可能是这样的
\documentclass[BCOR=10mm,DIV=calc]{scrreprt}
\usepackage[english,ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{libertine}
\usepackage{booktabs}
\usepackage{ragged2e}
\usepackage{ragged2e}
\usepackage{tabularx}
\newcommand\hd[1]{%
\multicolumn{1}{c}{\bfseries\centering\begin{tabular}{@{}c@{}}#1\end{tabular}}}
\begin{document}
\begin{table}
\caption{Test}
\scriptsize\sffamily
\begin{tabularx}{\textwidth}{
@{}>{\hspace{0pt}\centering\arraybackslash}p{1cm}
>{\RaggedRight\arraybackslash}X
>{\RaggedRight\arraybackslash}X
>{\RaggedRight\arraybackslash}X
>{\RaggedRight\arraybackslash}X
>{\RaggedRight\arraybackslash}X@{}}
\toprule
\hd{XYZ} & \hd{I want\\ to be\\ vertically\\ aligned} & \hd{Me too} &
\hd{And me\\ too} & \hd{Same here} & \hd{And again}\tabularnewline
\midrule
5-6 & I WANT TO BE TOP ALIGNED, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua\\
\bottomrule
\end{tabularx}
\end{table}
\noindent X\dotfill X
\end{document}