4

I'd like to make a nice section title using the pgfornament package in the \titleformat of the titlesec package.

When I use only one ornament on the left side it works.

\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage{pgfornament}

\begin{document}
\titleformat{\section}[block]{\parbox[c]{5em}{\pgfornament[width=4em]{17}}\begin{minipage}{0.7\textwidth}\normalfont\Large\bfseries}{\thesection}{1em}{}[\end{minipage}]

\chapter{Story}

\section*{Introduction}
\end{document}

ornament section

But when I want the ornament on both sides, it does not work.

\titleformat{\section}[block]{\parbox[c]{5em}{\pgfornament[width=4em]{17}}\begin{minipage}{0.7\textwidth}\normalfont\Large\bfseries}{\thesection}{1em}{}[\end{minipage}\parbox[c]{5em}{\pgfornament[width=4em]{18}}]

I get the following error message from pdflatex:

Chapter 1.
(/usr/share/texlive/texmf-dist/tex/generic/vectorian17.pgf)
Runaway argument?
c\@@par \ttl@endlongest \fi \endgroup \ttl@finmarks \@ifundefined {tt\ETC.
! Paragraph ended before \@iparbox was complete.
<to be read again> 
                   \par 
l.13 \section*{Introduction}

Any help would be much appreciated. Thank you in advance.

2

You need to enclose the whole content of the last optional argument in an extra pair of braces due to the optional arguments of the \parbox and of the \pgfornament:

\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage{pgfornament}

\begin{document}
\titleformat{\section}[block]
  {\parbox[c]{5em}{\pgfornament[width=4em]{17}}\begin{minipage}{0.7\textwidth}\normalfont\Large\bfseries}
  {\thesection}{1em}{}
  [{\end{minipage}\parbox[c]{5em}{\pgfornament[width=4em]{18}}}]
\chapter{Story}

\section*{Introduction}
\end{document}

enter image description here

To prevent an overfull \hbox, change the width for the minipage; perhaps you would also like the ornament to the right to be flushed:

\titleformat{\section}[block]{\parbox[c]{5em}{\pgfornament[width=4em]{17}}\begin{minipage}{\dimexpr\textwidth-10em\relax}\normalfont\Large\bfseries}{\thesection}{1em}{}
[{\end{minipage}\parbox[c]{5em}{\hfill\pgfornament[width=4em]{18}}}]

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.