简体   繁体   English

如何使用 bookdown::gitbook 作为输出对齐 Rmd 中的整个文本

[英]How to justify whole text in Rmd with bookdown::gitbook as output

I would like to justify all the text in my gitbook, but I couldn't find a solution.我想证明我的 gitbook 中的所有文本都是合理的,但我找不到解决方案。 So far I've tried:到目前为止,我已经尝试过:

  • Set the text-align as justified in the style/body, right after the YAML Header:将 text-align 设置为样式/正文中的两端对齐,就在 YAML 标头之后:

    <style> body { text-align: justify } </style>

It doesn't work.它不起作用。

  • Set the text-align as justified in div tag for the whole text:在 div 标签中为整个文本设置 text-align 为两端对齐:

    <div style="text-align:justify;"> my whole text </div>

It works, but the numbering of the topics are lost (probably with other features I didn't figure out).它有效,但主题的编号丢失了(可能还有我没有弄清楚的其他功能)。

The thing is, I don't want to lose any standard feature of the output from bookdown::gitbook but the "text-align" (which I want it to be justified).问题是,我不想丢失 bookdown::gitbook 输出的任何标准功能,而是“文本对齐”(我希望它是合理的)。

Also, it would be too much work to have to put a div tag in all the sentences.此外,必须在所有句子中放置一个 div 标签也太费力了。 Any help?有什么帮助吗?

Thanks in advance!提前致谢!

Put your CSS code in a css file, say, custom.css :将您的 CSS 代码放在一个 css 文件中,例如custom.css

body {
  text-align: justify;
}

Then include it via the css option (I don't know what you meant by "preamble" in your post; if it meant the LaTeX preamble, it would be the wrong place to put CSS):然后通过css选项包含它(我不知道你在帖子中所说的“序言”是什么意思;如果它意味着 LaTeX 序言,那么放置 CSS 将是错误的地方):

bookdown::gitbook:
  css: "custom.css"

If it doesn't work (I have tested it and it works for me), please provide a reproducible example, and ideally also a published (web) version of your example, so we can easily investigate your CSS.如果它不起作用(我已经测试过它并且对我有用),请提供一个可重现的示例,最好还提供您示例的已发布(网络)版本,以便我们可以轻松地调查您的 CSS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM