2

I am building a table in a NiceTabularX environment, and I have a small alignment issue. In one of my rows, I would like to have the content rotated by 90° (direct), centered horizontally and bottom-aligned vertically. However, if I use X[l,m] columns, the vertical alignment is perfect but I don't get the horizontally-centered alignment correct, and if I use X[c,m] I get the correct horizontally-centered alignment, but the vertical bottom alignment goes away. Using c type columns would bring the correct alignment on both sides, but then it's a nightmare to calculate the size of the columns to make sure my table has the right width in total (which is precisely why I use NiceTabularX and not NiceTabular).

Here is a simplified example that illustrates my problem:

\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}

If you have any idea how to make this work, I would be very grateful!

Have an excellent day,

Simon

Here is how it looks:

enter image description here

1 Answer 1

2
\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}

enter image description here

1
  • Thank you a million, it works perfectly well! I have to admit I would never have thought about putting \raggedright for that...
    – Simon
    Commented Jan 26, 2022 at 10:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .