Skip to content

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

Closed as duplicate

Description

@DmasterD

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

Activity

  1. muzimuzhi commented on Aug 4, 2023

    @muzimuzhi
    Contributor

    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.

  2. lvjr commented on Sep 7, 2025

    @lvjr
    Collaborator

    This is a duplicate of issue #365 (see this comment for the planned hspacing=fixed option).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions