# Migrating from suftesi to memoir: parcenter style for sections

I am migrating a document from the suftesi class to memoir (due to printing size problems). I have only one problem left: I need to replicate the parcenter style of suftesi for the sections, possibly without having to load the titlesec package (seems like overkill to me). Also, I use LuaLaTeX, so XeLaTeX specific solutions have to be ruled out.

It may also be helpful to know that I have modified the "standard" sectioning to always increment the section number (even for starred commands) but without printing the section name in the starred version (the opposite of the normal starred command). I included this code also.

So here is my mwe:

\documentclass[a4paper,showtrims, twoside, italian, openright,10pt]{memoir}
\usepackage{xparse}
\makeatletter

\let\@nt@ni\section

\RenewDocumentCommand{\section}{som}{%
\IfBooleanTF{#1}{%
\refstepcounter{section}%
\@nt@ni*{\thesection}
}{%
\IfValueTF{#2}{%
\@nt@ni[#2]{#3}%
}{%
\@nt@ni{#3}}}%
}
\usepackage{microtype}
\usepackage{lipsum}
\begin{document}
\chapter{a}
\section{Text}
\lipsum[1]
\end{document}


here is the result (please do not mind the fonts):

here is the target result, obtained with \documentclass[documentstructure=book,secstyle=parcenter,style=smallcaps8]{suftesi} (please do not mind the fonts or the text but the format only)

EDIT to summarise I want: small caps section titles, centered but one line below the section number.

• so allcaps rather than caps and small caps and a line break after the number? – David Carlisle May 21 '17 at 13:52
• @DavidCarlisle I need only the line break after the number. Those are smallcaps too in suftesi they are somewhat bigger than the normal text size, that's all – Moriambar May 21 '17 at 13:53

Here is a possible solution:

\documentclass[a4paper,showtrims, twoside, italian, openright,10pt]{memoir}
\usepackage{xparse}

\let\memoirsection\section

\RenewDocumentCommand{\section}{sO{#4}O{#4}m}{%
\begingroup
\IfBooleanTF{#1}{%
\refstepcounter{section}%
\memoirsection*{\thesection}%
}{%
\memoirsection[#2][#3]{#4}%
}%
\endgroup
}
\usepackage{microtype}
\usepackage{lipsum}

\setsecindent{0pt}
\setsechook{%
\setsecnumformat{\csname the##1\endcsname\par}%
\sethangfrom{\noindent##1}%
}
\newcommand{\twolinecenter}[1]{%
\hbox{\parbox[t]{\textwidth}{\scshape\centering#1}}%
}

\begin{document}

\chapter{a}
\section{Text}
\lipsum[2]

\end{document}


Note that, contrary to what the documentation of memoir seems to suggest, \setsecnumformat and \sethangfrom declarations in a hook aren't local to the stated sectional level, but will affect all other sectional levels. This is the reason for \begingroup and \endgroup in the redefinition of \section, that I made compatible with the two optional arguments of memoir.

• yes I wondered whether the global nature of the redeclaration was desired. We'll see... – David Carlisle May 21 '17 at 21:43
• Ok, this wins because of the explanation of the locality and globality of changes – Moriambar May 21 '17 at 21:59
• I'm not sure if is a bug that the changes affect also lower levels. It looks more as if enables "inheritance". You can always undo the definition by setting the lower level hook. – Ulrike Fischer May 21 '17 at 22:05
• @UlrikeFischer It also affects upper levels. Once you do \setsecnumformat{whatever} in the hook, this changes the definition of \@seccntformat. – egreg May 21 '17 at 22:07
• I can't see this, if I use e.g. \setsubsechook to add red color to the number it affects only subsection and subsubsection but not chapter and section. – Ulrike Fischer May 21 '17 at 22:10

seems like in memoir you just need

\setsecnumformat{\csname the#1\endcsname}
\sethangfrom{#1\par}


full document:

\documentclass[a4paper,showtrims, twoside, italian, openright,10pt]{memoir}
\usepackage{xparse}
\makeatletter

\let\@nt@ni\section

\RenewDocumentCommand{\section}{som}{%
\IfBooleanTF{#1}{%
\refstepcounter{section}%
\@nt@ni*{\thesection}
}{%
\IfValueTF{#2}{%
\@nt@ni[#2]{#3}%
}{%
\@nt@ni{#3}}}%
}

\setsecnumformat{\csname the#1\endcsname}
\sethangfrom{#1\par}

\usepackage{microtype}
\usepackage{lipsum}

• I would ask you how this works, but being memoir I know that some deep magic is involved. Obviously it works – Moriambar May 21 '17 at 21:38
• well not very deep magic normally latexs section head internals invokes \@hangfrom which makes a hanging paragraph hanging from the section number so in article you'd have a big \makeatletter block redefining internals but i noticed that memoir has a specific command that (just) redefined \@hangfrom so here I make it do \par so you get the number a paragraph break then the title – David Carlisle May 21 '17 at 21:41