![我如何重新定义小节并将它们放在左边?](https://linux22.com/image/408784/%E6%88%91%E5%A6%82%E4%BD%95%E9%87%8D%E6%96%B0%E5%AE%9A%E4%B9%89%E5%B0%8F%E8%8A%82%E5%B9%B6%E5%B0%86%E5%AE%83%E4%BB%AC%E6%94%BE%E5%9C%A8%E5%B7%A6%E8%BE%B9%EF%BC%9F.png)
答案1
您(错误地)使用了\titleformat
来删除章节和子章节编号,但您将编号和标题之间的空格值设置为1em
。使用选项,hang
即使标签的参数为空,此空格也会在标题前使用。因此,您必须将设置更改为
\titleformat{\subsection}[hang]{\bfseries}{}{0pt}{}
。
但最好将计数器更改secnumdepth
为0
,并使用来\titleformat*
更改小节的字体:
\documentclass{article}
\usepackage{lipsum}% only for dummy text
\usepackage{titlesec}
\titleformat{\section}[block]{\sffamily \Large \filcenter}{}{0pt}{}
\titleformat*{\subsection}{\bfseries}
\setcounter{secnumdepth}{0}
\begin{document}
\section{A section}
\subsection{A subsection}
\lipsum[1-2]
\end{document}
但我从你之前的问题中知道你使用scrreprt
。不要将该包titlesec
与 KOMA-Script 类一起使用!因此这里有一个建议KOMA-Script 命令:
\documentclass[12pt,chapterprefix,sfdefaults=false]{scrreprt}
\usepackage{lipsum}% only for dummy text
\setcounter{secnumdepth}{\chapternumdepth}% only parts and chapters should be numbered
\addtokomafont{disposition}{\mdseries}% only some headings should be bold
\RedeclareSectionCommand[font=\bfseries\large]{chapter}% does the same as \setkomafont{chapter}{\bfseries\large}
\renewcommand\raggedchapter{\centering}% center chapter headings
\RedeclareSectionCommand[font=\sffamily\Large]{section}% does the same as \setkomafont{section}{\sffamily\Large}
\RedeclareSectionCommand[font=\bfseries]{subsection}% does the same as \setkomafont{subsection}{\bfseries}
% format headings with style=section, eg. section, subsection and subsubsection
\let\originalsectionlinesformat\sectionlinesformat
\renewcommand\sectionlinesformat[4]{%
\Ifstr{#1}{section}
{\centering #3#4}% centers section headings
{\originalsectionlinesformat{#1}{#2}{#3}{#4}}% original definition for other section levels
}
\begin{document}
\chapter{Foo}
\section{A section}
\subsection{A subsection}
\lipsum[1-2]
\end{document}