sptr.net
    • about sptr.net
    • about me
  • Stories
    • NixImagery
    • Poetry
    • Tales of the Family
  • Pictures
    • NixImagery on Flickr
    • NixImagery on 500px
    • Wild Aye Photography
  • Tech
    • I was in the REME, I’ll have you know
    • Technical blog
  • Research
    • About my research
    • ORCID profile
    • Digital Education profile
    • The BBC’s Something Understood

    • PhD/Supervisors (login required)
    • Thesis (in work, login required)
    • Participants (login required)
    • Web services structure
    • Cotman Paints
    • Pixie Puzzles

Text alignment in quarto

A way to align text right in both pdf and html outputs in quarto documents.
Published

26th September 2025

Modified

5th November 2025

I am using Koma script document class scrbook. The following way to align right in both pdf and html outputs in quarto uses quarto/pandoc fenced block attributes.

In _quarto.yaml:

format:
  html:
    css: styles.css
  pdf:
    include-in-header:
      - text: |
          \usepackage{ragged2e}

in styles.css:

.flushright {
    text-align: right;
}

and in the document:

:::{.flushright data-latex=""}
This text is right-aligned in HTML and PDF.
:::

Example – right-aligned text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

data-latex="" causes pandoc to pass the flushright through to \(\LaTeX\) – without it, quarto regards the fenced block as html only and discards the flushright information.


This was posted as an answer in GitHub/quarto-dev/quarto-cli. Apparently, you don’t need the data- bit, but I haven’t tried that.

  • the NixImagery Post / Fugacious Ideas

  • © Copyright Nick Hood