Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibreOffice displays some pandoc docx tables too wide #2576

Closed
ghost opened this issue Dec 5, 2015 · 7 comments
Closed

LibreOffice displays some pandoc docx tables too wide #2576

ghost opened this issue Dec 5, 2015 · 7 comments

Comments

@ghost
Copy link

ghost commented Dec 5, 2015

A table was marked up as follows:

| Item          | Kilowatts     | Use            | Cost      |
|:--------------|--------------:|:---------------|----------:|
| Geothermal Plant | **`1250.0`** | Electricity  | **`4.4`**
| Houses        | **`13.7`**    | Shelter        | **`4.2`**

This produced the desired outcome in the PDF using ConTeXt:

context-table

But DOCX did not display all the columns:

docx-table

To resolve the issue, a different Markdown table format was used:

---------------------------------------------------------------------------
Item                        Kilowatts        Use               Cost
---------------             ---------------  ----------------  -----------
Geothermal Plant            **`1250.0`**     Electricity       **` 4.4`**

Houses                      **`13.7`**       Shelter           **` 4.2`**
---------------------------------------------------------------------------

This fixed the DOCX issue:

docx-table-resolved

And produced the following ConTeXt code:

\starttable[|lp(0.38\textwidth)|lp(0.23\textwidth)|lp(0.24\textwidth)|lp(0.15\textwidth)|]

Normally, that will produce a table. But my page layout settings are interfering with the amount of space allocated for the table, which prevents the table from appearing. But that's a side issue. The problem of concern is that the numeric columns are no longer right-justified:

context-table-justification

I'm able to reinstate the justification and force the table to appear using the following command:

sed -i 's!\\starttable\[.*\]$!\\starttable[|l|r|l|r|]!' filename.tex

It's a hack, though, and doesn't right-justify the columns in the DOCX (a minor issue).

There should be a way to use the first markdown table to produce similar results for both ConTeXt and DOCX.

@ghost ghost changed the title Trails and tribulations of table formats Trials and tribulations of table formats Dec 5, 2015
@jgm
Copy link
Owner

jgm commented Dec 5, 2015

Your table looks fine in both HTML and docx when I try it.

As for the second issue, in multiline tables, you control
the alignment of columns by positioning the column header
(see the manual).

If you want the Cost column to be right-justified, do it
like so:

Item                        Kilowatts        Use                      Cost
---------------             ---------------  ----------------  -----------

@ghost
Copy link
Author

ghost commented Dec 5, 2015

Using the table code (\starttable[|lp(0.38\textwidth)|rp(0.23\textwidth)...]) generates a table that does not have optimal widths (although it does have the desired justification now, thank you):

context-table-too-wide

The table extends beyond the text margins by about half an inch on either side.

Using sed to replace the code to (\starttable[|l|r|l|r|]) produces optimal widths:

context-table-optimal-width

It might be possible to tweak the ConTeXt macro for \starttable to use a smaller width, but if there was a way to force Pandoc to not use a \textwidth multiplier for these types of tables, that would be helpful.

Maybe there's something else I'm missing?

@jgm
Copy link
Owner

jgm commented Dec 6, 2015

If you use a simple table (rather than a multiline table - see the manual for the lingo) then you won't get explicit column widths.

@ghost
Copy link
Author

ghost commented Dec 6, 2015

Simple table doesn't produce output for DOCX that loads in either LibreOffice 4.4.6 or LibreOffice 5.0.3.

Item                              Kilowatts  Use                      Cost
----------------            ---------------  ----------------  -----------
Geothermal Plant            **`1250.0`**     Electricity       **` 4.4`**
Houses                      **`13.7`**       Shelter           **` 4.2`**

This was converted using:

pandoc -t docx 13.md -o 13.docx

Load it in LibreOffice v4.x or v5.x on Ubuntu Linux. The result is the same as before:

libreoffice-table

Since the double-spaced tables are working in LibreOffice, I dumped the XML for the double-spaced table (double-table.xml) and simple table (simple-table.xml), then performed a diff:

$ diff double-table.xml simple-table.xml 
16c16
<                 <w:tblW w:type="pct" w:w="5000.0" />
---
>                 <w:tblW w:type="pct" w:w="0.0" />
19,24c19
<             <w:tblGrid>
<                 <w:gridCol w:w="2996" />
<                 <w:gridCol w:w="1819" />
<                 <w:gridCol w:w="1926" />
<                 <w:gridCol w:w="1177" />
<             </w:tblGrid>
---
>             <w:tblGrid />

Perhaps <w:tblW w:type="pct" w:w="0.0" /> generated from the simple table is causing issues. Or maybe it's the lack of w:gridCol values. I've attached both XML files for your convenience. Let me know if there's anything else I can do to help resolve the issue.

tables.zip

@mvz
Copy link

mvz commented Dec 7, 2016

I'm running into this problem when converting from HTML to DOCX using pandoc. My particular problem would most probably be solved by either:

(For me, the issue surfaces as too-wide cells in LibreOffice, and extremely narrow cells in Pages.)

@jgm jgm changed the title Trials and tribulations of table formats LibreOffice displays some pandoc docx tables too wide Feb 27, 2017
@wkpalan
Copy link

wkpalan commented Nov 3, 2018

There seems to be workaround by setting the --columns options to a low value (e.g. 10), and that would trigger the correct table formatting in pandoc for libreoffice

pandoc -o test.default.docx test.md

Gives the following table xml in the document.xml

<w:tblPr>
    <w:tblStyle w:val="Table" />
    <w:tblW w:type="pct" w:w="0.0" />
    <w:tblLook w:firstRow="1" />
</w:tblPr>
<w:tblGrid />

The output in libreoffice

test default

Setting the --columns 10 gives a different table xml

pandoc  -o test.10.docx --columns 10 test.md

The table xml in the document.xml for --columns 10

<w:tblPr>
    <w:tblStyle w:val="Table" />
    <w:tblW w:type="pct" w:w="4999.999999999999" />
    <w:tblLook w:firstRow="1" />
</w:tblPr>
<w:tblGrid>
    <w:gridCol w:w="1100" />
    <w:gridCol w:w="1100" />
    <w:gridCol w:w="1100" />
    <w:gridCol w:w="1100" />
    <w:gridCol w:w="1100" />
    <w:gridCol w:w="1100" />
    <w:gridCol w:w="1320" />
</w:tblGrid>

The output in libreoffice

test 10

The test.md contained the following table content

## case 1

| aaa        | bbb        | ccc        | ccc        | ccc        | ccc        | ccc          |
| ---------- | ---------- | ---------- | ---------- | ----------: | ----------: | ------------ |
| aaaaaaaaaa | bbbbbbbbbb | cccccccccc | cccccccccc | cccccccccc | cccccccccc | cccccccccccc |
| aaaaaaaaaa | bbbbbbbbbb | cccccccccc | cccccccccc | cccccccccc | cccccccccc | cccccccccccc |
| aaaaaaaaaa | bbbbbbbbbb | cccccccccc | cccccccccc | cccccccccc | cccccccccc | cccccccccccc |
| aaaaaaaaaa | bbbbbbbbbb | cccccccccc | cccccccccc | cccccccccc | cccccccccc | cccccccccccc |

## case 2

| aaa        | bbb        | ccc        |
| ---------- | ---------: | ---------: |
| aaaaaaaaaa | bbbbbbbbbb | cccccccccc |
| aaaaaaaaaa | bbbbbbbbbb | cccccccccc |
| aaaaaaaaaa | bbbbbbbbbb | cccccccccc |
| aaaaaaaaaa | bbbbbbbbbb | cccccccccc |

@tarleb
Copy link
Collaborator

tarleb commented May 21, 2021

This was fixed via 0921b82.

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

No branches or pull requests

4 participants