0

I used titlesec to define the chapter headings for a Chinese book. However, as of texlive 2020 there are incompatibilities with Koma Script and titlesec (in my specific setting, I cannot produce a minimal example showing the conflict). I want to get rid of titlesec but I do not know how to reach the effects. What I am looking for is something to put the section number in the middle of the heading: "The 5th section".

\documentclass{scrbook}


\usepackage{titlesec}

\titleformat{\chapter}[block]{\center\Large\bfseries}{Chapter\thechapter{}Number}{20pt}{}  
\titleformat{\appendix}[block]{\center\Large\bfseries}{\appendixname}{20pt}{}  
\titleformat{\section}[block]{\large\bfseries}{\thesection}{10pt}{}  
\titleformat{\tableofcontents}[block]{\center\Large\bfseries}{Some special string}{20pt}{}  
\titleformat{\part}[block]{\center\Large\bfseries}{Part \thepart{} Number}{20pt}{}  

\begin{document}

\tableofcontents

\clearpage

\part{A part}

\chapter{Introduction}

\section{foo}

\section{bar}

\end{document}
Stefan Müller
  • 6,901
  • 3
  • 29
  • 61
  • have a look here -- https://tex.stackexchange.com/questions/36299/incompatibilities-between-koma-script-and-titlesec?rq=1 – js bibra May 05 '20 at 02:34
  • Yes, thanks! I saw this before, but these seem to be solutions to other problems. I need the section number in the middle of a string. Like "The 5th Section". – Stefan Müller May 05 '20 at 08:12

2 Answers2

3

I do not understand what \titleformat{\appendix} and \titleformat{\tableofcontents} should do: neither \appendix nor \tableofcontents is a sectioning command.

Your \titleformat macros for \part, \chapter and \section can be replaced by

\renewcommand*{\partformat}{Part \thepart{} Number\hspace{20pt}}
\renewcommand*{\partheadmidvskip}{}
\renewcommand*{\chapterformat}{\chapapp \thechapter Number\hspace{20pt}}
\renewcommand*{\raggedchapter}{\centering}
\renewcommand*{\sectionformat}{\thesection\hspace{10pt}}

\addtokomafont{disposition}{\rmfamily}
\setkomafont{partnumber}{\Large}
\setkomafont{part}{\Large}
\setkomafont{chapter}{\Large}
\setkomafont{section}{\large}

Example:

\documentclass{scrbook}

\renewcommand*{\partformat}{Part \thepart{} Number\hspace{20pt}}
\renewcommand*{\partheadmidvskip}{}
\renewcommand*{\chapterformat}{\chapapp \thechapter Number\hspace{20pt}}
\renewcommand*{\raggedchapter}{\centering}
\renewcommand*{\sectionformat}{\thesection\hspace{10pt}}

\addtokomafont{disposition}{\rmfamily}
\setkomafont{partnumber}{\Large}
\setkomafont{part}{\Large}
\setkomafont{chapter}{\Large}
\setkomafont{section}{\large}

\begin{document}
\tableofcontents
\part{A part}
\chapter{Introduction}
\section{foo}
\section{bar}
\end{document}

enter image description here

esdd
  • 85,675
  • Thanks a lot. Sorry for the appendix and toc. They can be set with renewcaptionname. This almost solves the problem, but the appendix shall have a heading like "附录 A ~~~ 练习题答案". With the current settings it comes out as "附录 A 练习题答案", that is there is no space after the "A". – Stefan Müller May 07 '20 at 05:43
  • Found a solution for the appendix. This was in the langsci class already. \appto\appendix{ % format of the appendix title page \renewcommand*{\chapterformat}{ \mbox{\chapapp~\thechapter\hspace{20pt}} } % format of the TOC entry \renewcommand{\addchaptertocentry}[2]{ \ifstr{#1}{}{ \addtocentrydefault{chapter}{}{#2} }{ \addtocentrydefault{chapter}{}{\chapapp~#1 #2} } } } – Stefan Müller May 07 '20 at 05:52
-1

Try the following definition with \phantom....

enter image description here

\documentclass{scrartcl}

\usepackage{titlesec}
% Incorrect ToC link to \addsec
% \titleformat{\section}{\Huge\sffamily}{\thesection}{0.5em}{}
% Correct ToC link to \addsec
\titleformat{\section}{\Huge\sffamily}{\thesection}{0.5em}{\phantomsection}

\usepackage{hyperref}

\begin{document}

    \tableofcontents

    \clearpage

    \section{foo}

    \clearpage

    \addsec{bar}

\end{document}
js bibra
  • 21,280