lvjr / tabularray

Typeset tabulars and arrays with LaTeX3
https://ctan.org/pkg/tabularray
247 stars 22 forks source link

The width of cells is not according to the X column ratio when using colsep. #427

Open DmasterD opened 11 months ago

DmasterD commented 11 months ago

I'm wanting to perfectly align cells of different tables with X columns, but that seems to be only possible when colsep is 0, see example below. Is this a real issue or am I doing something wrong? Most people won't notice with small colseps, but OCD people will notice.

\documentclass{article}
\usepackage{mwe}
\usepackage{tabularray, color, xparse, parskip}
\setlength{\parindent}{0pt}

\NewDocumentEnvironment{tableNoColsep}{m +b}{
    \begin{tblr}{
        colspec = {#1},
        colsep = 0pt,
        vlines = {black}}
        #2
    \end{tblr}%
}{}
\NewDocumentEnvironment{tableColsep}{m +b}{
    \begin{tblr}{
        colspec = {#1},
        colsep = 1cm,
        vlines = {black}}
        #2
    \end{tblr}%
}{}

\begin{document}
\section*{Cell horizontal spacing issues}
\subsection*{Good spacing}
Tables with three cells of equal spacing:

\begin{tableNoColsep}{XXX}
    1 & 2 & 3
\end{tableNoColsep}
\begin{tableColsep}{XXX}
    1 & 2 & 3
\end{tableColsep}

Tables with one cell of a third, and another of two thirds of the width:

\begin{tableNoColsep}{X[1]X[2]}
    1 & 2+3
\end{tableNoColsep}
\begin{tableNoColsep}{X[2]X[1]}
    1+2 & 3
\end{tableNoColsep}

\subsection*{Bad spacing}
The following tables should be divided one cell of a third, and another of two thirds of the width:

\begin{tableColsep}{X[1]X[2]}
    1 & 2+3
\end{tableColsep}
\begin{tableColsep}{X[2]X[1]}
    1+2 & 3
\end{tableColsep}

\subsection*{Expected behavior}
\begin{tableNoColsep}{X[1]X[2]}
    \hspace{1cm}1\hspace{1cm} & \hspace{1cm}2+3\hspace{1cm}
\end{tableNoColsep}
\begin{tableNoColsep}{X[2]X[1]}
    \hspace{1cm}1+2\hspace{1cm} & \hspace{1cm}3\hspace{1cm}
\end{tableNoColsep}

\end{document}

image

muzimuzhi commented 11 months ago

Is this a real issue or am I doing something wrong?

I'm afraid that's a "real issue". leftsep, rightsep (colsep set them both) and vertical rule width of an X column are extracted from the total target width of all X columns, after that the width of X[1] is calculated by dividing the target width by sum of coefficients.

https://github.com/lvjr/tabularray/blob/690e67ee175ff7601d0144c84f9a7e9c67573e0b/tabularray.sty#L4074-L4081 https://github.com/lvjr/tabularray/blob/690e67ee175ff7601d0144c84f9a7e9c67573e0b/tabularray.sty#L4124-L4130

According to the doc for tabu package, sec. 1.2 "X column widths computation", tabu does the calculation in the same order.