【问题标题】:how to center h1 and h2 html headings in pdf file generated by pandoc如何在pandoc生成的pdf文件中居中h1和h2 html标题
【发布时间】:2021-06-04 23:45:03
【问题描述】:

我有一个简单的问题。我的 html 文件中有一些标题。类似的东西

<h1>H1 heading</h1>
<h2>H1 heading</h2>

我想使用 pandoc 让它在生成的文档中居中。

我尝试在我的 html 中添加如下内容:

<style>
h1, h2 {
  text-align:center
}
</style>

但这并没有帮助。你有一些想法如何尽可能简单地做到这一点?

非常感谢您的回答

【问题讨论】:

    标签: html css pdf latex pandoc


    【解决方案1】:

    您的代码应该可以正常工作,但这取决于您将其放置在何处。

    不使用 .css 的旧样式应该在 &lt;head&gt;...&lt;/head&gt;

    <!DOCTYPE html>
    <html>
    
    <head>
    
    <style>
    h1, h2 {
      text-align:center
    }
    </style>
    
    </head>
    
    <body>
    <h1>H1 heading</h1>
    Hello World
    <h2>H2 heading</h2>
    Hello Space
    </body>
    
    </html>
    

    如果上述行为不当,请向 Pandoc 提出错误报告

    我不确定您为什么使用 Pandoc,因为除非您安装大量 LaTeX 依赖项,否则您将使用 Wkhtmltox,它单独(没有 Pandoc)完成任务

    wkhtmltox\bin\wkhtmltopdf.exe file://test.htm test.pdf

    【讨论】:

    • 感谢您的回答 :) 我使用 Pandoc 是因为我需要简单的工具来仅使用控制台从 html 创建 pdf 文件,因为它将在 docker 容器中使用。我的 html 由 shell 脚本填充,甚至添加了一张图片,我看到 Pandoc 做得很好,但我会尝试wkhtmltopdf,也许它更容易:)
    猜你喜欢
    • 2017-07-16
    • 1970-01-01
    • 2015-04-11
    • 2012-09-30
    • 1970-01-01
    • 2010-11-12
    • 2016-11-14
    • 2012-09-17
    • 1970-01-01
    相关资源
    最近更新 更多