2

When I use ragged2e with \Centering, this causes underfull errors when used in titlesec.

As far as I know, I broke no functionality using the titlesec package.

\documentclass{article}

\usepackage{ragged2e}

\usepackage{titlesec} 
\usepackage{indentfirst}
\usepackage{microtype}
\usepackage{lipsum}

% Enable numbering for paragraphs and subparagraphs
\setcounter{secnumdepth}{5}

% Define the section formatting using titlesec
\titleformat{\section}
  {\Centering\scshape}
  { \Roman{section}.\space}
  {0em}
  {}
\titleformat{\subsection}
  {\Centering\scshape}
  { \Roman{section}.\Roman{subsection}.\space}
  {0em}
  {}
\titleformat{\subsubsection}
  {\Centering\scshape}
  { \Roman{section}.\Roman{subsection}.\Roman{subsubsection}.\space}
  {0em}
  {}
\titleformat{\paragraph}
  {\Centering\scshape}
  { \Roman{section}.\Roman{subsection}.\Roman{subsubsection}.\Roman{paragraph}.\space}
  {0em}
  {}
\titleformat{\subparagraph}
  {\Centering\scshape}
  { \Roman{section}.\Roman{subsection}.\Roman{subsubsection}.\Roman{paragraph}.\Roman{subparagraph}.\space}
  {0em}
  {}

% Adjust spacings for sections
\titlespacing*{\section}{0pt}{0pt}{0pt}
\titlespacing*{\subsection}{0pt}{0pt}{0pt}
\titlespacing*{\subsubsection}{0pt}{0pt}{0pt}
\titlespacing*{\paragraph}{0pt}{0pt}{0pt}
\titlespacing*{\subparagraph}{0pt}{0pt}{0pt}

% Patch \paragraph and \subparagraph to behave like other sectioning commands
\makeatletter
\patchcmd{\paragraph}{\@startsection{paragraph}{4}}{\@startsection{paragraph}{4}{}{\z@}}{}{}
\patchcmd{\subparagraph}{\@startsection{subparagraph}{5}}{\@startsection{subparagraph}{5}{}{\z@}}{}{}
\makeatother

\setlength\parindent{.25cm} 

\begin{document}

\section{Introduction}

Taylor Swift's success is a testament to her exceptional talent and unwavering determination. Since her debut in 2006, Swift has achieved remarkable milestones, including multiple Grammy Awards and chart-topping albums across various genres. Her transition from country music to pop was not only seamless but also marked by groundbreaking achievements, such as her album 1989 becoming one of the best-selling records of the decade. Swift's strategic reinventions and her ability to connect deeply with audiences have resulted in a string of record-breaking tours and an ever-expanding global fanbase. Beyond commercial success, she has become a powerful voice in the industry, advocating for artists' rights and influencing the evolution of modern music. Swift's career is characterized by a series of bold moves and artistic successes, underscoring her status as one of the most influential musicians of her generation.

\subsection{One}

\end{document}

I've had a question regarding \RaggedRight and it causing overfull errors and got excellent answers, but could not find an answer that tackles what affects me right now with `\Centering'. I would greatly appreciate if someone could help me with my issue.

5
  • 2
    Use \centering.
    – cfr
    Commented Jul 26 at 6:24
  • 2
    Ragged2e commands cause underfull boxes by design on one line paragraphs so aren't really suitable for headings Commented Jul 26 at 6:25
  • @DavidCarlisle why does \let\Centering\centering work even though Ragged2e has \let\centering\Centering?
    – cfr
    Commented Jul 26 at 6:28
  • 1
    @cfr the latter is not the default only if you use the unreconmended option to overwrite the standard commands Commented Jul 26 at 6:31
  • @DavidCarlisle so why does \show\Centering still then say \protect\Centering?
    – cfr
    Commented Jul 26 at 7:37

1 Answer 1

5

titlesec has \filcenter for this purpose and I guess that the package author introduced \filcenter, \filleft and \filright in order to cope with ragged2e that can overwrite \centering, \raggedleft and \raggedright.

I also simplify the code. In particular the patches you tried to \paragraph and \subparagraph did nothing at all.

\documentclass{article}

\usepackage{ragged2e}

\usepackage{titlesec} 
\usepackage{indentfirst}
\usepackage{microtype}
\usepackage{lipsum}

% Enable numbering for paragraphs and subparagraphs
\setcounter{secnumdepth}{5}

\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\thesection.\Roman{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection.\Roman{subsubsection}}
\renewcommand{\theparagraph}{\thesubsubsection.\Roman{paragraph}}
\renewcommand{\thesubparagraph}{\theparagraph.\Roman{subparagraph}}

% Define the section formatting using titlesec
\titleformat{\section}
  {\filcenter\scshape}
  {\thesection.\ }
  {0em}
  {}
\titleformat{\subsection}
  {\filcenter\scshape}
  {\thesubsection.\ }
  {0em}
  {}
\titleformat{\subsubsection}
  {\filcenter\scshape}
  {\thesubsubsection.\ }
  {0em}
  {}
\titleformat{\paragraph}
  {\filcenter\scshape}
  {\theparagraph.\ }
  {0em}
  {}
\titleformat{\subparagraph}
  {\filcenter\scshape}
  {\thesubparagraph.\ }
  {0em}
  {}

% Adjust spacings for sections
\titlespacing*{\section}{0pt}{0pt}{0pt}
\titlespacing*{\subsection}{0pt}{0pt}{0pt}
\titlespacing*{\subsubsection}{0pt}{0pt}{0pt}
\titlespacing*{\paragraph}{0pt}{0pt}{0pt}
\titlespacing*{\subparagraph}{0pt}{0pt}{0pt}

\setlength\parindent{.25cm} 

\begin{document}

\section{Introduction}

\lipsum[1][1-4]

\subsection{One}

\lipsum[1][1-2]

\subsubsection{Test}

\paragraph{Test}

\subparagraph{Test}

\lipsum[1][1-2]

\end{document}

output

You must log in to answer this question.

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