Skip to content

grid_table: alignments lost when near cell colspan #10855

@kysko

Description

@kysko

Using latest pandoc-nightly-windows-2025-05-20.

The table

+----------+----+
| h1       | h2 |
+:===:+===:+:===+
| A        | B  |
+-----+----+----+
| C   | D  | E  |
+-----+----+----+

will give the following correct alignments in the AST when read:

    [ ( AlignCenter , ColWidth 8.333333333333333e-2 )
    , ( AlignRight , ColWidth 6.944444444444445e-2 )
    , ( AlignLeft , ColWidth 6.944444444444445e-2 )
    ]

However, when written as a grid_table, we get:

+-------------+----+
| h1          | h2 |
+:===========:+:===+
| A           | B  |
+------+------+----+
| C    | D    | E  |
+------+------+----+

So we lost the right-alignment on the second column (which should affect cell D for example).
The expected result should look like the original table.


For the table:

+-----+----+----+
| h1  | h2 | h3 |
+:===:+===:+:===+
| A        | B  |
+-----+----+----+
| C   | D  | E  |
+-----+----+----+

we get:

+------+------+----+
| h1   | h2   | h3 |
+:=====+=====:+:===+
| A           | B  |
+------+------+----+
| C    | D    | E  |
+------+------+----+

which is also problematic: the first column is now left-align.


For the table:

+----------+----+
| h1       | h2 |
+:===:+===:+:===+
| A   | F  | B  |
+-----+----+----+
| C   | D  | E  |
+-----+----+----+

we get a proper result.

So it's the influence of the cell colspan below which cause trouble, at least in these examples.


The alignments being a global property of the table, they should not be affected by nearby cell colspans.

A suggestion would be to always write all the alignements segments on the header separator/border.
As a compromise, one could relax this when there is no ambiguïty (eg for default aligns on columns affected by nearby colspans).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions