6

I would like to justify all the text in my gitbook, but I couldn't find a solution. So far I've tried:

  • Set the text-align as justified in the style/body, right after the YAML Header:

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

It doesn't work.

  • Set the text-align as justified in div tag for the whole text:

    <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).

Also, it would be too much work to have to put a div tag in all the sentences. Any help?

Thanks in advance!

1
  • 1
    pity this didnt get an answer! Jun 15, 2019 at 5:34

1 Answer 1

7

Put your CSS code in a css file, say, 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):

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.

2
  • 1
    Thank you very much, @Yihui Xie! It works! About the "preamble", I made a mistake. What I actually meant is "YAML header". I've edited that info in the post. Thank you again, and congrats for your work! Best! Jun 24, 2019 at 13:58
  • 1
    This worked for me as well. Thanks so much!
    – Martin
    Jan 16 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.