如何使用 pandoc 语法在 Markdown 文档中指定表格?

发布于 2024-10-09 14:28:35 字数 203 浏览 0 评论 0原文

我有一个 Markdown 文档,正在使用 pandoc 工具处理以生成 HTML 和 PDF 文档。我正在尝试在文档中包含一个表格。常规 Markdown 不支持表格,但 pandoc 支持。我尝试将 pandoc 文档中的表定义复制粘贴到我的源文档中,但是当通过 pandoc 程序运行它时,生成的文档全部塞进一张大表中。

谁能告诉我一个可以正确渲染的 pandoc 表?

I have a markdown document I'm processing with the pandoc tool to generate HTML and PDF documents. I'm trying to include a table in the document. Regular markdown doesn't support tables, but pandoc does. I've tried copy-pasting the definition of a table from the pandoc documentation into my source document, but when running it through the pandoc program the resulting document is all crammed into one big table.

Can anyone show me a pandoc table that renders properly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

困倦 2024-10-16 14:28:35
# Points about Tweedledee and Tweedledum

Much has been made of the curious features of 
Tweedledee and Tweedledum.  We propose here to
set some of the controversy to rest and to uproot
all of the more outlandish claims.

    .      Tweedledee       Tweedledum
--------   --------------   ----------------
Age        14               14
Height     3'2"             3'2"
Politics   Conservative     Conservative
Religion   "New Age"        Syrian Orthodox
---------  --------------   ----------------

Table: T.-T. Data


# Mussolini's role in my downfall

--------------------------------------------------------------------
             *Drugs*         *Alcohol*           *Tobacco*
----------   -------------   -----------------   --------------------
    Monday     3 Xanax        2 pints             3 cigars,  
                                                  1 hr at hookah bar

   Tuesday    14 Adderall     1 Boone's Farm,     1 packet Drum
                              2 Thunderbird

 Wednesday    2 aspirin       Tall glass water    (can't remember)
---------------------------------------------------------------------

Table:  *Tableau des vices*, deluxe edition


# Points about the facts

In recent years, more and more attention has been 
paid to opinion, less and less to what were formerly 
called the cold, hard facts.  In a spirit of traditionalism, 
we propose to reverse the trend. Here are some of our results.

-------     ------ ----------   -------
     12     12        12             12
    123     123       123           123
      1     1          1              1
---------------------------------------

Table:  Crucial Statistics


# Recent innovations (1): False presentation

Some, moved by opinion and an irrational lust for novelty, 
would introduce a non-factual element into the data, 
perhaps moving all the facts to the left:

-------     ------ ----------   -------
12          12     12           12
123         123    123          123
1           1      1            1
---------------------------------------

Table: Crucial "Statistics"

# Recent innovations (2): Illegitimate decoration

Others, preferring their facts to be *varnished*, 
as we might say, will tend to 'label' the columns

Variable    Before During       After
---------   ------ ----------   -------
12          12     12           12
123         123    123          123
1000        1000   1000         1000
----------------------------------------

# Recent innovations (3): "Moderate" decoration

Or, maybe, to accompany this 'spin' with a centered or centrist representation: 

 Variable    Before  During       After
----------  ------- ----------   -------
 12          12      12           12
 123         123     123          123
 1           1       1            1
-----------------------------------------


# The real enemy

Some even accompany these representations with a bit of leftwing 
clap-trap, suggesting the facts have drifted right:


------------------------------------------------------
  Variable       Before            During       After
----------  -----------        ----------     -------
 12                  12                12          12
              -- Due to
                baleful 
              bourgeois
              influence

  123               123               123          123
              -- Thanks
              to the 
              renegade 
               Kautsky

  1                   1                 1            1
              -- All a 
              matter of
            sound Party
             discipline
-------------------------------------------------------

Table: *"The conditions are not ripe, comrades; they are **overripe**!"*

# The Truth

If comment be needed, let it be thus:  the facts have drifted left.


------------------------------------------------------------------------
 Variable   Before             During            After
----------  -------------      ----------        ----------------------
 12         12                 12                12
            (here's            (due to           (something to do
            where the rot      lapse of          with Clinton and
            set in )           traditional       maybe the '60's)
                               values)

 123        123                123               123
            (too much          (A=440?)
            strong drink)

 1          1                  1                 1
                                                 (Trilateral Commission?)
--------------------------------------------------------------------------

Table: *The Decline of Western Civilization*
# Points about Tweedledee and Tweedledum

Much has been made of the curious features of 
Tweedledee and Tweedledum.  We propose here to
set some of the controversy to rest and to uproot
all of the more outlandish claims.

    .      Tweedledee       Tweedledum
--------   --------------   ----------------
Age        14               14
Height     3'2"             3'2"
Politics   Conservative     Conservative
Religion   "New Age"        Syrian Orthodox
---------  --------------   ----------------

Table: T.-T. Data


# Mussolini's role in my downfall

--------------------------------------------------------------------
             *Drugs*         *Alcohol*           *Tobacco*
----------   -------------   -----------------   --------------------
    Monday     3 Xanax        2 pints             3 cigars,  
                                                  1 hr at hookah bar

   Tuesday    14 Adderall     1 Boone's Farm,     1 packet Drum
                              2 Thunderbird

 Wednesday    2 aspirin       Tall glass water    (can't remember)
---------------------------------------------------------------------

Table:  *Tableau des vices*, deluxe edition


# Points about the facts

In recent years, more and more attention has been 
paid to opinion, less and less to what were formerly 
called the cold, hard facts.  In a spirit of traditionalism, 
we propose to reverse the trend. Here are some of our results.

-------     ------ ----------   -------
     12     12        12             12
    123     123       123           123
      1     1          1              1
---------------------------------------

Table:  Crucial Statistics


# Recent innovations (1): False presentation

Some, moved by opinion and an irrational lust for novelty, 
would introduce a non-factual element into the data, 
perhaps moving all the facts to the left:

-------     ------ ----------   -------
12          12     12           12
123         123    123          123
1           1      1            1
---------------------------------------

Table: Crucial "Statistics"

# Recent innovations (2): Illegitimate decoration

Others, preferring their facts to be *varnished*, 
as we might say, will tend to 'label' the columns

Variable    Before During       After
---------   ------ ----------   -------
12          12     12           12
123         123    123          123
1000        1000   1000         1000
----------------------------------------

# Recent innovations (3): "Moderate" decoration

Or, maybe, to accompany this 'spin' with a centered or centrist representation: 

 Variable    Before  During       After
----------  ------- ----------   -------
 12          12      12           12
 123         123     123          123
 1           1       1            1
-----------------------------------------


# The real enemy

Some even accompany these representations with a bit of leftwing 
clap-trap, suggesting the facts have drifted right:


------------------------------------------------------
  Variable       Before            During       After
----------  -----------        ----------     -------
 12                  12                12          12
              -- Due to
                baleful 
              bourgeois
              influence

  123               123               123          123
              -- Thanks
              to the 
              renegade 
               Kautsky

  1                   1                 1            1
              -- All a 
              matter of
            sound Party
             discipline
-------------------------------------------------------

Table: *"The conditions are not ripe, comrades; they are **overripe**!"*

# The Truth

If comment be needed, let it be thus:  the facts have drifted left.


------------------------------------------------------------------------
 Variable   Before             During            After
----------  -------------      ----------        ----------------------
 12         12                 12                12
            (here's            (due to           (something to do
            where the rot      lapse of          with Clinton and
            set in )           traditional       maybe the '60's)
                               values)

 123        123                123               123
            (too much          (A=440?)
            strong drink)

 1          1                  1                 1
                                                 (Trilateral Commission?)
--------------------------------------------------------------------------

Table: *The Decline of Western Civilization*
往日情怀 2024-10-16 14:28:35

另一种选择是使用 GitHub markdown 表 更容易格式化,因为它们不需要与空格字符对齐,

  • 您可以使用管道 | 创建表和连字符 -。连字符用于创建每列的标题,而管道则分隔每列。您必须在表格前添加一个空行才能正确呈现。
  • 桌子两端的管道是可选的。
  • 单元格的宽度可以不同,并且不需要在列内完美对齐。标题行的每列中必须至少有三个连字符。
  • 您可以通过在标题行中连字符的左侧、右侧或两侧添加冒号 : 来将文本与列的左侧、右侧或中心对齐。
  • 单元格文本中的管道字符需要转义

在此处输入图像描述

并且上面的表格格式也会在 Stackoverflow 中呈现...

命令说明注释
git status列出所有新的或修改的文件,此右对齐
git diff显示尚未存在的文件差异没有上演这是一个字面意思|

Pandoc 能够将 GitHub 风格的 markdown

pandoc --from=gfm -- 转换为:pdf -o 表.pdf 表.md

Another option is to use GitHub markdown tables which are easier to format since they don't require alignment with empty space characters,

  • You can create tables with pipes | and hyphens -. Hyphens are used to create each column's header, while pipes separate each column. You must include a blank line before your table in order for it to correctly render.
  • The pipes on either end of the table are optional.
  • Cells can vary in width and do not need to be perfectly aligned within columns. There must be at least three hyphens in each column of the header row.
  • You can align text to the left, right, or center of a column by including colons : to the left, right, or on both sides of the hyphens within the header row.
  • pipe characters within cell's text need to be escaped

enter image description here

and the above table format renders in Stackoverflow too...

CommandDescriptionNotes
git statusList all new or modified filesthis right aligned
git diffShow file differences that haven't been stagedThis is a literal |

Pandoc is able to convert GitHub flavoured markdown,

pandoc --from=gfm --to:pdf -o table.pdf table.md

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文