Closed ghost closed 3 years ago
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
--------------- --------------- ---------------- -----------
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):
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:
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?
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.
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:
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.
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.)
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
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
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 |
This was fixed via 0921b82d98b6ec7fa80ffd522c129b3828b9c00b.
A table was marked up as follows:
This produced the desired outcome in the PDF using ConTeXt:
But DOCX did not display all the columns:
To resolve the issue, a different Markdown table format was used:
This fixed the DOCX issue:
And produced the following ConTeXt code:
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:
I'm able to reinstate the justification and force the table to appear using the following command:
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.