法语二/三/四/五节编号,带手动换行

法语二/三/四/五节编号,带手动换行

作为我上一个问题的后续法语章节编号使用 bis、ter 等,我尝试手动在章节标题中添加换行符,这些换行符会按预期显示在正文中,但不会在目录中手动换行。我希望这很清楚 - 如果不是,下面的屏幕截图应该可以显示我想要的内容:

按章节拆分,但不按目录拆分

我使用手动章节编号实现了这一点,而这正是我在第一个问题中试图避免的。其语法如下:

\documentclass{book}
\usepackage{xparse}
\usepackage{enumitem}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage{titletoc}


\titleformat{\section}[block]{\normalfont\normalsize\itshape\filcenter}{\thesection. ---}{0.5em}{}
\renewcommand\thesection{\arabic{section}}

\begin{document}
\tableofcontents

\section{First section header}
\lipsum[1]
\section*{1 \textit{bis}. --- Second section header is very long \\ and I want to control the location where it breaks}\addcontentsline{toc}{section}{1 \textit{bis}    Second section header is very long and I want to control the location where it breaks}
\lipsum[4]

\end{document}

以下是基于语法的无效 MWE姆维尼在上述问题中提出。请注意,我没有使用此语法来得到上面的图像。如果我尝试在此语法的章节标题中放置换行符,则编译失败。

\documentclass{book}
\usepackage{xparse}
\usepackage{enumitem}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}
\usepackage{titletoc}


\ExplSyntaxOn
\seq_new:N \bislist
\seq_set_split:Nnn \bislist {;} {bis;ter;quater;quinquies;sexies;septies;octies;novies;decies}
\NewDocumentCommand {\bisprint} {m}
 {
  \seq_item:Nn \bislist {#1}
 }
\ExplSyntaxOff

\newcounter{bis}
\stepcounter{bis}
\titleformat{\section}[block]{\normalfont\normalsize\itshape\filcenter}{\thesection. --- #1}{0.5em}{}[\setcounter{bis}{1}]
\renewcommand\thesection{\arabic{section}}
\titleformat{name=\section,numberless}[block]{\normalfont\normalsize\itshape\filcenter}{\arabic{section} \textit{\bisprint{\arabic{bis}}}. --- #1}{0.5em}{}[ \addcontentsline{toc}{section}{\numberline{\arabic{section} \textit{\bisprint{\arabic{bis}}}}#1} \stepcounter{bis}]

\makeatletter
\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{3.5em}} %change the last parameter to 2.5em if you do not go further that ter and to 3.5 if you don't go further than quater
\makeatother


\begin{document}
\tableofcontents

\section{First section header}
\lipsum[1]
\section*{Second section header is very long and I want to control the location where it breaks}
\lipsum[4]

\end{document}

答案1

这里有一个选项:使用特殊(强健)宏\bodyonlynewline作为手动换行技术。此宏只会换行正文中的行,而不会换行目录。

在此处输入图片描述

\documentclass{book}
\usepackage{xparse}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}

\ExplSyntaxOn
\seq_new:N \bislist
\seq_set_split:Nnn \bislist {;} {bis;ter;quater;quinquies;sexies;septies;octies;novies;decies}
\NewDocumentCommand {\bisprint} {m}
 {
  \seq_item:Nn \bislist {#1}
 }
\ExplSyntaxOff

\newcounter{bis}
\stepcounter{bis}
\titleformat{\section}[block]{\normalfont\normalsize\itshape\filcenter}{\thesection. --- #1}{0.5em}{}[\setcounter{bis}{1}]
\renewcommand\thesection{\arabic{section}}
\titleformat{name=\section,numberless}[block]{\normalfont\normalsize\itshape\filcenter}{\arabic{section} \textit{\bisprint{\arabic{bis}}}. --- #1}{0.5em}{}[ \addcontentsline{toc}{section}{\protect\numberline{\arabic{section} \textit{\bisprint{\arabic{bis}}}}#1} \stepcounter{bis}]

\makeatletter
\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{3.5em}} %change the last parameter to 2.5em if you do not go further that ter and to 3.5 if you don't go further than quater
\makeatother
\DeclareRobustCommand{\bodyonlynewline}{}% Macro does nothing
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
  \oldtableofcontents
  \DeclareRobustCommand{\bodyonlynewline}{\\}% Macro breaks line only _after_ ToC
}

\begin{document}
\tableofcontents

\section{First section header}
\lipsum[1]
\section*{Second section header is very long \bodyonlynewline and I want to control the location where it breaks}
\lipsum[4]

\end{document}

注意在的格式\protect\numberline中使用。否则numberless\section扩张\numberline可能会引起问题

相关内容