我正在环境中构建表格NiceTabularX
,但遇到了一个小的对齐问题。在我的其中一行中,我希望将内容旋转 90°(直接),水平居中并垂直对齐底部。但是,如果我使用X[l,m]
列,垂直对齐是完美的,但我无法获得正确的水平居中对齐,如果我使用,X[c,m]
我会获得正确的水平居中对齐,但垂直底部对齐会消失。使用 c 类型的列会在两侧带来正确的对齐,但计算列的大小以确保我的表格总宽度正确是一场噩梦(这正是我使用NiceTabularX
和而不是的原因NiceTabular
)。
这是一个说明我的问题的简化示例:
\documentclass[12pt,a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{nicematrix}
\begin{document}
With \verb!X[l]! style columns, I get the correct vertical alignment to the bottom of the row, but the elements are not horizontally centered:
\def\arraystretch{1}
\begin{NiceTabularX}{9cm}{X[l]X[l]X[l]X[l]}[hvlines]
\RowStyle{\rotate}
\textmd{Short} & \textmd{Verylong} & \textmd{T} & \textmd{Medium} \\
& F & G & H \\
I & J & \Block{1-2}{KL} & \\
M & N & O & P\\
\end{NiceTabularX}
\vspace{5mm}
With \verb!X[c]! style columns, I get the correct vertical alignment to the bottom of the row, but the elements are not horizontally centered anymore:
\def\arraystretch{1}
\begin{NiceTabularX}{9cm}{X[c]X[c]X[c]X[c]}[hvlines]
\RowStyle{\rotate}
\textmd{Short} & \textmd{Verylong} & \textmd{T} & \textmd{Medium} \\
& F & G & H \\
I & J & \Block{1-2}{KL} & \\
M & N & O & P\\
\end{NiceTabularX}
\vspace{5mm}
With \verb!c! style columns, I get the right result in terms of alignments, but unfortunately I really have to work with the \verb!NiceTabularX! environment to get the total width of my table correct:
\def\arraystretch{1}
\vspace{5mm}
\begin{NiceTabularX}{9cm}{cccc}[hvlines]
\RowStyle{\rotate}
\textmd{Short} & \textmd{Verylong} & \textmd{T} & \textmd{Medium} \\
& F & G & H \\
I & J & \Block{1-2}{KL} & \\
M & N & O & P\\
\end{NiceTabularX}
\end{document}
如果您知道如何实现这一点,我将不胜感激!
祝您有美好的一天,
西蒙
它看起来是这样的:
答案1
\documentclass[12pt,a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabularX}{9cm}{*{4}{X[c]}}[hvlines]
\RowStyle{\rotate\raggedright\arraybackslash}
\textmd{Short} & \textmd{Verylong} & \textmd{T} & \textmd{Medium} \\
& F & G & H \\
I & J & \Block{1-2}{KL} & \\
M & N & O & P\\
\end{NiceTabularX}
\end{document}