6

In LuaLaTeX, I have the following code that allows for me to have a section that is not numbered, and that has the text centered, with smallcaps font style on. I thought the text looked a but not on the centered, and i tried to test out if i was just seeing it wrong, and yes, i was correct. When {\centering\textsc{Problem 1.}\par} and \begin{center}\textsc{Problem 1.}\end{center} are typed, they result in something that is spaced differently from \section{Problem 1.}.

\documentclass[letterpaper,12pt]{article}

\usepackage{microtype}
\usepackage{titlesec}
    \titleformat{\section}
    {\scshape\centering} % format
    {} % label % replace with {\thesection. } if need the section number on sections.
    {0cm} % sep
    {} % before-code
    \titlespacing*{\section}
    {0cm} % left
    {0cm} % before
    {0cm} % after

\begin{document}

\begin{center}
    \textsc{Problem 1.}
\end{center}

{\centering\textsc{Problem 1.}\par}

\section{Problem 1.}

\end{document}

The culprit is the microtype package, as when taking it away, it will have {\centering\textsc{Problem 1.}\par} and \begin{center}\textsc{Problem 1.}\end{center} be the same as \section{Problem 1.}. It seems that microtype adds unnecessary space to those two, and I'm not sure why.

Can anyone provide any insight on this, or any way to fix this and make it correctly adjusted? it would be a big help.

4
  • 3
    I'm not sure it's correct to say that "the culprit is the microtype package". For sure, if I replace your titlesec-based formatting instructions with \usepackage{sectsty} and \sectionfont{\centering\normalfont\normalsize\scshape}, then \section*{Problem 1.} has no problem with centering.
    – Mico
    Commented Mar 8 at 5:38
  • Off-topic: it really isn't a good idea to remove all the stretch in vertical spacing around section titles. It's not just that the defaults introduce vertical space. They also include flexible space which helps TeX break pages in good places. If you remove that, you'll generally get poorer results.
    – cfr
    Commented Mar 8 at 6:29
  • @Mico It is some sort of interaction, I guess, since removing microtype also gets correct alignment. But I'm more than happy to blame titlesec ;).
    – cfr
    Commented Mar 8 at 6:32
  • a one-off solution would be to insert the protrusion manually: \section{Problem 1\rightprotrusion{.}} Commented Mar 8 at 8:45

2 Answers 2

5

Apparently the problem is with titlesec's insertion of struts to keep some vertical distances consistent.

If you insist on using titlesec, a possible fix (if it really bothers you and doesn't upset spacings) could be the following MWE:

\documentclass[letterpaper,12pt]{article}

\usepackage{microtype}
\usepackage{titlesec}
\titleformat{\section}
{\nostruts\scshape\filcenter} % format
{} % label % replace with {\thesection. } if need the section number on sections.
{0cm} % sep
{} % before-code
\titlespacing*{\section}
{0cm} % left
{0cm} % before
{0cm} % after

\begin{document}
    
    \begin{center}
        \textsc{Problem 1.}
    \end{center}
    
    {\centering\textsc{Problem 1.}\par}
    
    \section{Problem 1.}
    
\end{document}

Output of MWE

1
  • 2
    With \usepackage[nostruts]{titlesec} one globally disables struts.
    – egreg
    Commented Mar 8 at 7:57
3

Here's an alternative which achieves the section format you want without titlesec and, so, avoids the problem.

\documentclass[letterpaper,12pt]{article}
\usepackage{microtype}

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {2.3ex \@plus.2ex}%
  {\normalfont\scshape\centering}}
\makeatother
\setcounter{secnumdepth}{0}
\begin{document}

\begin{center}
    \textsc{Problem 1.}
\end{center}

{\centering\textsc{Problem 1.}\par}

\section{Problem 1.}

\end{document}

three unproblematic problems

You must log in to answer this question.

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