Search code examples
latexpandoc

Pandoc: How to get a horizontal rule in pipe table in addition to top and bottom


I'm trying to create a table which has a horizontal rule across the width of the table, in addition to the horizontal rules which are created automatically at the top and bottom of the table. I'm trying to make do that with pipe tables, but if someone knows a way to do it with another kind of table, I'd be interested to hear about that too.

pandoc --version reports "pandoc 2.9.2.1; Compiled with pandoc-types 1.20, texmath 0.12.0.2, skylighting 0.8.5".

I have tried variations on the following.

My first table.

|  ABC  |  DEF  |  GHI  |  JKL  |
|:-----:|:-----:|:-----:|:-----:|
|  1    |  123  | 456   |  789  |
|  2    |  234  | 567   |  890  |
|  3    |  345  | 678   |  901  |
|———————|———————|———————|———————|
|       |  111  | 222   |  333  |
  : Foo bar baz quux, mumble blurf.

Note the Unicode EM DASH (U+2014) in the penultimate line -- using hyphen instead of EM DASH yields pretty much the same output, except that pandoc mixes EM DASH and hyphen in the output (most of the horizontal bars are EM DASH, but in some of them, the final character is hyphen, which is noticeably misaligned with EM DASH; I assume the presence of hyphen is a bug).

What I get from the above input is the following PDF output.

enter image description here

That's not too bad, but I would prefer (1) to have a continuous horizontal rule across the width of the table, not separate segments per column, and (2) to have the same thickness and color as the horizontal rule under the column titles.


Solution

  • Of all the table formats supported by pandoc Markdown, there's only one that supports tables with footer rows: grid tables. The below should give the desired results (requires pandoc 3 or newer).

    +-----+-----+-----+-----+
    | ABC | DEF | GHI | JKL |
    +:===:+:===:+:===:+:===:+
    | 1   | 123 | 456 | 789 |
    +-----+-----+-----+-----+
    | 2   | 234 | 567 | 890 |
    +-----+-----+-----+-----+
    | 3   | 345 | 678 | 901 |
    +=====+=====+=====+=====+
    |     | 111 | 222 | 333 |
    +=====+=====+=====+=====+
      : Foo bar baz quux, mumble blurf.
    

    Table with footer


    Also note that, if you have more specific requirements, you could always try to use a LaTeX table instead of a Markdown table, and then use the parse-latex Lua filter to parse it when converting to other formats.