-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Add a style for tables in docx writer #3275
Comments
Here are the official instructions. Create a reference.docx:
pandoc --print-default-data-file reference.docx > myref.docx
Open this with Word. Change the "Normal Table" (or "Table
Normal") style to match what you want. Save. Then invoke pandoc with
pandoc --reference.docx myref.docx yourinput.html -o youroutput.docx
PROBLEM! This doesn't work, because you can't modify
"Normal Table" (at least I couldn't).
So I think we need some changes in pandoc to make this
possible. This site
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-mso_other/i-nead-to-edit-the-format-normal-table-how-do-i-do/ab27db4e-a7c3-432f-8d3a-6c5f274f2d6a
recommends creating a custom table style, and we could do
that, and use it for pandoc tables.
@jkr any thoughts?
|
You can automatically change default headers, text, lists styles only. |
@jgm -- from what's posted it looks like the best way. I'm not too familiar, but I'll take a look -- probably tomorrow. |
+1 |
+1 |
Hi, Thanks |
Hi, I'm experiencing the same problem as asknet. Help would be appreciated ! Thanks |
Same issue here. I have the latest version of pandoc installed (1.19.2.1). I tried the method refenreced in the official docs (the Then I tried editing the output docx file, like what the author of this post said in the I think maybe the official docs could be more clearified about this certain issue, as it takes too much for a user who isn't familiar with the specs of the docx format to make the "right" change, still without significant improvement to this tiny yet critical spot (since all other parts of the convertion were just perfect). Or there could be some args that defines some custom table style I'd like to use in the reference file, as the Normal Table isn't allowed to be modified. Thanks! |
@mogita the fix is not in 1.19.2.1, it's only in the dev version. |
this feature can be quite useful |
@jgm do you know when this fix will be integrated in the release by any chance? Cheers. |
I would be very interested in this feature as well |
This should be released as of now, in pandoc 2.0 |
I also have the same problem.There is no border in the table in the docx file I generated.Please help me. |
@yang-small-fan did you edit the table style in your reference docx to fit your needs? |
@agusmba I edit the form style in the reference template, but it doesn't seem to work.It still has no border. |
Hey @yang-small-fan - it's my understanding that Pandoc's docx writer creates tables with a Style named "Table", so you need to make sure that you apply styling changes in your "reference-doc" to this particular Table Style. According to the comment above, I believe you also need to be running Pandoc 2.0 or later, as well... |
@iandol According to the official website prompt, the custom-reference.docx form I generated seems to have some problems, but I can't modify it. My pandoc version is 2.1.1, and office version is 2016.. |
@yang-small-fan - I just opened the reference doc you attached to your comment, edited the "Table" style (setting "All Borders"), saved the reference doc, then tested the amended reference doc by passing a simple Markdown file through Pandoc. It worked fine for me, so I'm not sure where things aren't quite working out for you. Here's modified copy of your reference doc, a source markdown file (for testing purposes), and the docx output file in case they help you:
I'm on Mac OS, so the process I went through to change the Table Style in MS Word was as follows:
Here are some screenshots in case they help: |
@iansco I used your docx template to generate the correct form, but I also like you to add a border form to my template. At the same time, I don't know why my template didn't work after conversion. I guess it's the MS Word version or the reason of the operation system. In a word, the problem has been solved. I'm very grateful to you. (๑′ᴗ‵๑)I Lᵒᵛᵉᵧₒᵤ❤ |
@yang-small-fan bear in mind that you need to edit the Table Style called "Table" as @iansco explained beautifully. It won't work if you only edit a table with that style in your reference docx. |
Thanks @yang-small-fan :-) When using Pandoc to create docx output I've found the Options affecting specific writers section in the Pandoc manual to be helpful - specifically, the section titled Docx under This section provides a list of all the Styles which Pandoc uses. You'll see that Pandoc only currently uses a single Table Style named So - as per the comment immediately above (thanks @agusmba!) - if you want to change the styling of any Tables in your docx output, you'll need to make sure you edit the Table Style named There are other ways to affect the style of docx output (see Custom Styles in Docx Output and filters), but that's a discussion for another day :-) Good luck! P.S. if you find you're still having problems applying styling changes to your |
Hey @iandol I now need to convert the HTML file into a word file. Is there a way to keep the style in HTML? |
@yang-small-fan AFAIK styles from html do not go through pandoc to docx directly, but simple copy-paste might get you halfway there (from browser into word). Once you have your desired styles in a word document, you can use that one as |
@iansco Your methods almost work for my, thanks a lot! The "almost": This is what I requested in the template, no decorations for last row, and first/last column: This is created by knitr/Pandoc. Too bad, "Last Row" and Last/First Column are selected. Everything is fine when I manually correct the Options setting for each table. This could be done by a Macro, but does anyone know a method to set these options in the Template? In case no other solution is found: this is my Macro
|
I have the same problem as @dmenne. Even though "Total Row" and "Last Column" are unchecked in my reference document, the columns still appear in my generated docx document. |
PLEASE update this issue |
I edit in Markdown, and plan to convert to Word. The original instructions https://support.office.com/en-us/article/format-a-table-e6e77bc6-1f4e-467e-b818-2e2acc488006#bm1 |
…Word cf. jgm/pandoc#3275 pour plus d'explication sur la difficulté de modifié le style "Table"
I figured out how to change the table format in reference.docx at last.
|
add filter and custom your own Table style, see lua filter: https://github.com/ZhouJunjun/TyporaLuaFilter |
Can I Change default "Table" style name to my custom style name? Because I have some other Table here, I want some table owned its custom name. |
Changing the default Table style isn't enough previously. Recently, I created a Word Macro to cope with this issue. Sub TableStyleFix()
Dim atable As Table
For Each atable In ActiveDocument.Tables
If atable.Columns.Count > 2 Then
atable.Style = ("Custom Table")
End If
Next
End Sub
Sub TableAutoFitWindow()
Dim atable As Table
For Each atable In ActiveDocument.Tables
If atable.Columns.Count > 2 Then
atable.AutoFitBehavior (wdAutoFitWindow)
End If
Next
End Sub
Sub TableDistributeColumns()
Dim atable As Table
For Each atable In ActiveDocument.Tables
If atable.Columns.Count > 2 Then
atable.Columns.DistributeWidth
End If
Next
End Sub
Sub TableAutoAdjust()
Application.Run MacroName:="TableStyleFix"
Application.Run MacroName:="TableAutoFitWindow"
Application.Run MacroName:="TableDistributeColumns"
End Sub You can create a custom table style named "Custom Table" or anything you like. Just Run the TableAutoAdjust Macro. Using auto-fit-window and distribute-columns will be a good choice, although not suitable for small tables. I use this for tables with more than 2 columns because if you use pandoc-crossref, subfigures will mostly be rendered as a two-column table. The reason I created separate macros is that an all-in-one macro only works in debug mode and you have to run it step by step. Not sure why, but using |
thanks you so much! |
When I convert HTML table to docx using pandoc (ver 1.18), I would like to change the table style for MS-word(docx).
I used the following Pandoc command for conversion (HTML table to docs)
HTML table code
Web browser result:
MS Word result (after conversion):
Howe can I change MS-word(docx) table styles as follows when I convert HTML table to docx using pandoc ?
The text was updated successfully, but these errors were encountered: