3

I would like to center one of my sub-headers not the text below it. I tried the code below and it centers the subheading and also the text in the subsection.

---
title: "how do I center only a title"
format: html
---
### Something

something not centered

### A Centered Subheading {style="text-align: center;"}

Blah blah

- Blah
- More blah
- still more blah

### Somethingelse

not centered

What is the proper way to center just the subtitle?

itsMeInMiami
  • 2,324
  • 1
  • 13
  • 34
  • Applying custom CSS? – shafee Jul 12 '22 at 14:16
  • Hello @shafee Sadly, I don't know enough CSS to do it. I tried ### [A Centered Subheading]{style="text-align: center;"} and nothing was centered. The code above centers the entire section. – itsMeInMiami Jul 12 '22 at 14:27

1 Answers1

4

You can center a specific header using css. Simply define a class name for that header like here I have used .test as a class applied to that header. And then in a separate css file styles.css, we need to write the style rules.

---
title: "how do I center only a title"
format: html
css: styles.css
---

### Something

something not centered


### A Centered Subheading {.test}


Blah blah

- Blah
- More blah
- still more blah

### Somethingelse

not centered

And In the styles.css file

.test h3 {
  text-align: center;
}

Output

quarto_doc_with_a_header_centered

shafee
  • 15,566
  • 3
  • 19
  • 47