pandoc icon indicating copy to clipboard operation
pandoc copied to clipboard

HTML reader: width on style attribute of table does not influence column widths

Open twiggler opened this issue 2 years ago • 6 comments

Explain the problem. command: pandoc --output --to docx reference-doc=custom-reference.docx report-8660595912627799385.html

Pandoc version? pandoc.exe 2.14.2 windows

bugreport.zip

When table has inline style width: 100% as in the second table I expect the docx table to have full width, i.e. image I think the key is <w:tblW w:w="5000" w:type="pct" />

However, currently the resulting layout autofits the contents of the table cells, and is not full width.

twiggler avatar Oct 11 '21 14:10 twiggler

does it also happen without reference-doc=custom-reference.docx ?

mb21 avatar Oct 11 '21 14:10 mb21

This has nothing to do with docx specifically. You can reproduce using -f html -t native, giving the following representation of the table:

, Table
    ( ""
    , []
    , [ ( "style"
        , "border-collapse: collapse; width: 99.5575%; height: 22px;"
        )
      , ( "border" , "1" )
      ]
    )
    (Caption Nothing [])
    [ ( AlignDefault , ColWidthDefault )
    , ( AlignDefault , ColWidthDefault )
    ]
    (TableHead ( "" , [] , [] ) [])
    [ TableBody
        ( "" , [] , [] )
        (RowHeadColumns 0)
        []
        [ Row
            ( "" , [] , [ ( "style" , "height: 22.3984px;" ) ] )
            [ Cell
                ( ""
                , []
                , [ ( "style" , "width: 50.0443%; height: 22.3984px" ) ]
                )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "Aa" ] ]
            , Cell
                ( ""
                , []
                , [ ( "style" , "width: 50.0443%; height: 22.3984px" ) ]
                )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                [ Plain [ Str "Bbb" ] ]
            ]
        , Row
            ( "" , [] , [ ( "style" , "height: 22.3984px;" ) ] )
            [ Cell
                ( ""
                , []
                , [ ( "style" , "width: 50.0443%; height: 22.3984px" ) ]
                )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                []
            , Cell
                ( ""
                , []
                , [ ( "style" , "width: 50.0443%; height: 22.3984px" ) ]
                )
                AlignDefault
                (RowSpan 1)
                (ColSpan 1)
                []
            ]
        ]
    ]
    (TableFoot ( "" , [] , [] ) [])
]

As you can see, the style information is included in an attribute. But it isn't taken account of in determining the column widths, since we have:

    [ ( AlignDefault , ColWidthDefault )
    , ( AlignDefault , ColWidthDefault )

It would be possible to modify the HTML reader to look at the width component of the style attribute and use this in computing widths. In this case, though, we'd have to set both columns to 0.5 full width, since there isn't other information here about the relative widths to use.

jgm avatar Oct 11 '21 15:10 jgm

Is this issue planned to be resolved in the near future? and is there a fix or trick to specify the width of table cells?

elearning202 avatar Aug 09 '22 13:08 elearning202

You can use <col> elements with relative widths.

jgm avatar Aug 09 '22 17:08 jgm