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

How to set a custom-style for a table? #6496

Open
kugelblitz opened this issue Jul 1, 2020 · 5 comments
Open

How to set a custom-style for a table? #6496

kugelblitz opened this issue Jul 1, 2020 · 5 comments

Comments

@kugelblitz
Copy link

Hello,

My task is to allow to set a Word table style (e. g. table without borders) in Pandoc Markdown.

In some previous version of pandoc (2.1.1) I used the following trick to apply a custom table style in the generated docx:

  1. Put the Markdown table into a paragraph with :::{custom-style=MyParagraphStyle}, where MyParagraphStyle does not have any importance of its own -- it just serves as a marker for the postprocessing.
  2. Generate docx with Pandoc. Table cells will have MyParagraphStyle as their paragraph style.
  3. Do some postprocessing in Powershell where I search for such tables and then apply MyTableStyle to them. MyTableStyle is a table style properly defined in the reference docx.

In Pandoc 2.9.2 and probably in 2.10, it no longer works. Pandoc no longer lets the style of the paragraph the table is in leak into the table cells.

Is this an intended change? Do I have any other ways to achieve my goal? Thanks.

@jgm
Copy link
Owner

jgm commented Jul 1, 2020

IT might be this change in 2.8:

    + Preserve built-in styles in DOCX with custom style (Ben Steinberg,
      #5670).  This change prevents custom styles on divs and spans
      from overriding styles on certain elements inside them, like
      headings, blockquotes, and links. On those elements, the
      "native" style is required for the element to display correctly.
      This change also allows nesting of custom styles; in order to do so,
      it removes the default "Compact" style applied to Plain blocks,
      except when inside a table.

@jgm
Copy link
Owner

jgm commented Jul 1, 2020

If you're postprocessing anyway, you could do something like put the word "SPECIALTABLE" before the table. Postprocessing script would have to find this and strip it out.

@kugelblitz
Copy link
Author

I tackled the problem by moving the custom-style into the first cell of the table, and having the postprocessing script checking the style of the first cell. I see that some work is planned on table styles in #4697, so maybe some day the postprocessing hack will be gone.

@tomtom
Copy link

tomtom commented Mar 31, 2022

Could we please reopen this issue? I had to downgrade to version 2.7.1 in order to get the old behaviour back. This is extremely annoying.

With 2.7.1, you could write:

::: {custom-style="TD"}
| A | B |
| 1 | 2 |
:::

If you defined the style TD in a docx reference document, the table cells were formatted in the referenc document's TD paragraph style.

The same could be done for verbatim code etc.

After 2.7.1 (or so), this doesn't work anymore. Table cells, verbatim code etc. don't get formatted with the proper style.

I'm not entirely sure whether 2.7.1 is the last good version. I used this based upon the above comment. I tried 2.14 and 2.17.1.1 and these versions don't work properly.

@jgm jgm reopened this Mar 31, 2022
@metorm
Copy link

metorm commented Dec 20, 2023

I want this, too.

pandoc-crossref uses a table to format equation numbers.

If we cannot used different table styles for different tables, all equations would be formated like other tables.

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

No branches or pull requests

4 participants