5

I want to add an ornament (provided by the pgfornament package) after the section title's body. Here is a MWE which produces the error I get (the document compiles correctly if I remove \pgfornament[width=0.25\textwidth]{70}):

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}


\usepackage[object=vectorian]{pgfornament}
\usepackage[calcwidth]{titlesec}
\titleformat{\section}[block]{\centering}{\thesection\\}{0pt}{\huge}[\pgfornament[width=0.25\textwidth]{70}]
\begin{document}
\lipsum[1]
\section{A section}
\lipsum[2]
\end{document}

I want it to look like :

                                                section number
                                                section title
                                                   ornament

1 Answer 1

6

You need to use \protect

\titleformat{\section}[block]{\centering}{\thesection\\}{0pt}{\huge}[\protect{\pgfornament[width=0.25\textwidth]{70}}]

enter image description here

1
  • Awesome lovely answer! For my case, how do I place the Number before the Section Title (on the same line) and how do I modify the spacing between Title and ornament?
    – Leon
    Dec 2, 2022 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .