Как выровнять по центру длинные заголовки, которые переносятся в оглавление?

Как выровнять по центру длинные заголовки, которые переносятся в оглавление?

У меня есть некоторые заголовки разделов и подразделов, которые занимают более одной строки в моем TOC. Мой TOC выровнен по центру, но мои заголовки, которые обтекают, не выравниваются по центру?

\documentclass{memoir}
\let\ordinal\relax

% TOC title
\makeatletter
\renewcommand{\printtoctitle}[1]{\centering\HUGE\textit{Contents}}

% TOC
\usepackage{fmtcount}
\setcounter{tocdepth}{2}

\makeatletter
\patchcmd{\l@chapapp}{{\cftchapterfont {#1}}\nobreak}{\cftchapterfont {#1}\nobreak}{\typeout{ok}}{\typeout{bad}}

% Chapter
\setlength\cftchapternumwidth{0pt}
\renewcommand{\thechapter}{\Numberstring{chapter}}
\renewcommand{\cftchapterleader}{}
\renewcommand{\cftchapterfillnum}[1]{\hspace*{10pt}\Huge#1\hfil\strut\par}
\renewcommand*{\cftchapterfont}{}
\renewcommand\chapternumberline[1]{\hfil\LARGE\emph{#1}\hfil\strut\Huge\par\nopagebreak\hfil}

% Section
\renewcommand{\cftsectionleader}{}
\renewcommand{\thesection}{}
\renewcommand{\cftsectionfillnum}[1]{\itshape\hspace*{10pt}\LARGE#1\cftparfillskip\par}
\renewcommand*{\cftsectionfont}{\itshape\LARGE\hfil}

% Subsection
\renewcommand{\cftsubsectionleader}{}
\renewcommand{\cftsubsectionfillnum}[1]{\hspace*{10pt}\LARGE#1\cftparfillskip\par}
\renewcommand*{\cftsubsectionfont}{\itshape\LARGE\hfil}

% Spacing
\setlength{\cftbeforechapterskip}{0pt}

% Document
\begin{document}
\tableofcontents*
\chapter{Chapter One}
\chapter{Chapter Two}
\chapter{Chapter Three}
\chapter{Chapter Four}
\section{Section One}
\subsection{Subsection One}
\section{Section Two}
\subsection{Subsection Two}
\subsection{Subsection Three, Which Has a\\Really Long Title}
\chapter{Chapter Five}
\end{document}

\makeatother   

введите описание изображения здесь

решение1

Снова снимите пару распорок и перейдите к использованию\centering

% Section
\setlength\cftsectionnumwidth{0pt}
\renewcommand{\cftsectionleader}{}
\renewcommand{\thesection}{}
\renewcommand{\cftsectionfillnum}[1]{\itshape\hspace*{10pt}\LARGE#1\par}
\renewcommand*{\cftsectionfont}{\centering\itshape\LARGE}

\patchcmd{\l@section}{{\@nameuse{cftsectionfont}{#1}}\nobreak}{\@nameuse{cftsectionfont}{#1}\nobreak}{\typeout{ok}}{\typeout{bad}}


% Subsection
\setlength\cftsubsectionnumwidth{0pt}
\renewcommand{\cftsubsectionleader}{}
\renewcommand{\cftsubsectionfillnum}[1]{\hspace*{10pt}\LARGE#1\par}
\renewcommand*{\cftsubsectionfont}{\centering\itshape\LARGE}

\patchcmd{\l@subsection}{{\@nameuse{cftsubsectionfont}{#1}}\nobreak}{\@nameuse{cftsubsectionfont}{#1}\nobreak}{\typeout{ok}}{\typeout{bad}}

Совет: если вы используете \ShowCommand\l@sectionкомпиляцию, \l@sectionв журнале будет отображаться текущий код.

решение2

Это слишком сложно. Однако для достижения цели лучше переопределить команду \l@chapapp, \l@sectionи \l@subsection.

Еще один день не хочу работать :)

\documentclass{memoir}
\let\ordinal\relax

% TOC title

\renewcommand{\printtoctitle}[1]{\centering\HUGE\textit{Contents}}

% TOC
\usepackage{fmtcount}
\setcounter{tocdepth}{2}
\setcounter{secnumdepth}{0}

\usepackage{tikz}

% Chapter
\renewcommand{\thechapter}{\Numberstring{chapter}}
\renewcommand{\cftchapternumwidth}{0pt}
\renewcommand{\cftbeforechapterskip}{20pt}
\renewcommand{\cftchapterfillnum}[1]{}
\renewcommand{\cftchapterfont}{\itshape\Huge}
\renewcommand\chapternumberline[1]{{\Large#1\\[5pt]}}
\makeatletter
\def\l@chapapp#1#2#3{%
\ifnum \c@tocdepth >\m@ne \cftchapterbreak \vskip
\cftbeforechapterskip \centering\begin{minipage}[b]{0.5\textwidth}
\centering\parindent \cftchapterindent
\relax \@afterindenttrue \interlinepenalty \@M \leavevmode \let \@cftbsnum
\cftchapterpresnum \let \@cftasnum \cftchapteraftersnum \let \@cftasnumb
\cftchapteraftersnumb \def \@chapapp@head {#3}\settowidth {\@tempdima
}{\cftchapterfont \@chapapp@head }\addtolength {\@tempdima }{\cftchapternumwidth
}\advance \memRTLleftskip \@tempdima \null \nobreak {\cftchapterfont {#1}}\nobreak \cftchapterfillnum {#2}\end{minipage}\tikz[remember picture, overlay]{\node [anchor=text,font=\cftchapterfont] at (0.5,0) {#2};}\par\fi%
}
\makeatother

% Section
\renewcommand{\cftsectionindent}{0pt}
\renewcommand{\cftsectionnumwidth}{0pt}
\renewcommand{\cftbeforesectionskip}{15pt}
\renewcommand{\cftsectionfillnum}[1]{}
\renewcommand{\cftsectionfont}{\itshape\LARGE}

\makeatletter
\def\l@section#1#2{%
\ifnum \@nameuse {c@tocdepth} > 0\relax \vskip \@nameuse
{cftbeforesectionskip}\centering\begin{minipage}[b]{0.5\textwidth}
\centering\newcommand *\cftwhatismyname {section}\parindent \@nameuse {cftsectionindent}\relax \@afterindenttrue
\interlinepenalty \@M \leavevmode \settowidth {\@tempdima }{\@nameuse
{cftsectionfont}{\@nameuse {cftsectionname}}}\addtolength {\@tempdima
}{\@nameuse {cftsectionnumwidth}}\expandafter \let \expandafter \@cftbsnum
\csname cftsectionpresnum\endcsname \expandafter \let \expandafter
\@cftasnum \csname cftsectionaftersnum\endcsname \expandafter \let
\expandafter \@cftasnumb \csname cftsectionaftersnumb\endcsname \expandafter
\let \expandafter \@cftn@me \csname cftsectionname\endcsname \advance
\memRTLleftskip \@tempdima \null \nobreak {\@nameuse {cftsectionfont}{#1}}\nobreak \@nameuse {cftsectionfillnum}{#2}\end{minipage}\tikz[remember picture, overlay]{\node [anchor=text,font=\cftsectionfont] at (0.5,0) {#2};}\par\fi%
}
\makeatother

% Subsection
\renewcommand{\cftsubsectionindent}{0pt}
\renewcommand{\cftsubsectionnumwidth}{0pt}
\renewcommand{\cftbeforesubsectionskip}{10pt}
\renewcommand{\cftsubsectionfillnum}[1]{}
\renewcommand{\cftsubsectionfont}{\itshape\Large}

\makeatletter
\def\l@subsection#1#2{%
\ifnum \@nameuse {c@tocdepth} > 1\relax \vskip \@nameuse
{cftbeforesubsectionskip}\centering\begin{minipage}[b]{0.5\textwidth}
\centering\newcommand *\cftwhatismyname
{subsection}  \parindent
\@nameuse {cftsubsectionindent}\relax\@afterindenttrue \interlinepenalty
\@M \leavevmode \settowidth {\@tempdima }{\@nameuse {cftsubsectionfont}{\@nameuse
{cftsubsectionname}}}\addtolength {\@tempdima }{\@nameuse {cftsubsectionnumwidth}}\expandafter
\let \expandafter \@cftbsnum \csname cftsubsectionpresnum\endcsname
\expandafter \let \expandafter \@cftasnum \csname cftsubsectionaftersnum\endcsname
\expandafter \let \expandafter \@cftasnumb \csname cftsubsectionaftersnumb\endcsname
\expandafter \let \expandafter \@cftn@me \csname cftsubsectionname\endcsname
\advance \memRTLleftskip \@tempdima \null \nobreak 
{\@nameuse {cftsubsectionfont}{#1}}\nobreak \@nameuse {cftsubsectionfillnum}{#2}
\end{minipage}\tikz[remember picture, overlay]{\node [anchor=text,font=\cftsubsectionfont] at (0.5,0) {#2};}\par\fi%
}
\makeatother

% Document
\begin{document}
\tableofcontents*
\chapter{Chapter One Which Has a Really Long Long Long Title}
\chapter{Chapter Two}
\chapter{Chapter Three}
\chapter{Chapter Four}
\section{Section One}
\subsection{Subsection One}
\section{Section Two}
\subsection{Subsection Two}
\subsection{Subsection Three, Which Has a Really Long Long Long Long Long Long Long Long Long Title}
\chapter{Chapter Five}
\end{document}

введите описание изображения здесь

Связанный контент