如何在Quarto文档中实现文本两端对齐?
如何在Quarto中实现文本两端对齐
Quarto支持为不同输出格式(HTML、PDF、Word)设置文本两端对齐,以下是对应解决方案:
HTML 格式实现方法
HTML输出默认文本左对齐,需通过自定义CSS实现两端对齐:
内联CSS(单文档生效)
在文档中插入以下CSS代码块,即可让全文本自动调整单词间距实现两端对齐:
<style> body { text-align: justify; text-justify: inter-word; /* 优化英文单词间距 */ } </style>
修改后的完整示例:
--- title: "How to justify text in Quarto" format: html editor: visual --- <style> body { text-align: justify; text-justify: inter-word; } </style> ## Quarto Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>. Quarto is based on Pandoc and uses its variation of markdown as its underlying document syntax. Pandoc markdown is an extended and slightly revised version of John Gruber's Markdown syntax. Markdown is a plain text format that is designed to be easy to write, and, even more importantly, easy to read:
全局CSS文件(多文档复用)
创建一个style.css文件,内容同上,然后在YAML中引用:
--- title: "How to justify text in Quarto" format: html: css: style.css editor: visual ---
PDF 格式实现方法
Quarto生成PDF依赖LaTeX,默认文本即为两端对齐。若未生效,可在YAML中显式设置:
--- title: "How to justify text in Quarto" format: pdf: latex-options: ["justify"] ---
Word 格式实现方法
自定义参考文档
- 打开空白Word文档,将正文样式设置为两端对齐(对应你图中高亮的按钮)。
- 保存文档为
reference.docx。 - 在Quarto的YAML中引用:
--- title: "How to justify text in Quarto" format: docx: reference-doc: reference.docx ---
Pandoc参数设置
直接在YAML中添加参数实现:
--- title: "How to justify text in Quarto" format: docx: pandoc_args: ["--variable=bodytext:justify"] ---
内容的提问来源于stack exchange,提问作者Quinten
相关产品推荐
相关产品推荐

