更改章节和小节格式不会影响标题

更改章节和小节格式不会影响标题

我想要以下文档结构:

练习 1 %sections
a) %subsections
b)
练习 2

我发现以下解决方案是将章节标题放在编号之前并更改小节编号格式:

\renewcommand{\thesubsection}{\alph{subsection})}
\titleformat{\section}[runin]{\normalfont\Large\bfseries}{}{0pt}{#1\ \thesection\\}
\titleformat{\subsection}[runin]{\normalfont\large\bfseries}{}{0pt}{#1\ \thesubsection\\}

顺便问一下:我可以将整个小节部分向右移动吗?

但是我使用 scrlayer-scrpage 包来定义页脚和页眉。在内部页脚中,文本应显示练习编号,即章节编号。因此我为此使用了 \headmark,但它总是在术语“练习”之前显示数字。我该如何更改它?

这是一个最小的例子:

% !TeX encoding = UTF-8
\documentclass[a4paper,10pt,headsepline,footsepline,abstracton,notitlepage]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{scrlayer-scrpage}
\usepackage[explicit]{titlesec}

\renewcommand{\thesubsection}{\alph{subsection})}

\titleformat{\section}[runin]{\normalfont\Large\bfseries}{}{0pt}
{#1\ \thesection\\}
\titleformat{\subsection}[runin]{\normalfont\large\bfseries}{}{0pt}
{#1\ \thesubsection\\}

\automark{section}
\clearpairofpagestyles
\ihead{Author}
\ohead{\today}

\ifoot{\headmark}
\cfoot{Course xxx }
\ofoot{\pagemark}

\author{Chuck Norris}
\date{\today}

\title{xxx - Sheet 42}

\begin{document}


\maketitle
\begin{abstract}
    asdfahadga
\end{abstract}

\newpage

\section{Exercise}
tsestsfadf
\newpage
\subsection{Part }
asdf
\newpage
\section{Exercise}
\subsection{Part}
asdfadga
\subsection{Part}
\newpage

\end{document}

答案1

要更改页眉或页脚中节文本和数字的顺序,请重新定义\sectionmark

\renewcommand*\sectionmark[1]{%
  \markright{#1 \ifnumbered{section}{\sectionmarkformat}{}}%
}
\renewcommand*\sectionmarkformat{\thesection}

但请注意,不建议titlesec与 KOMA-Script 类一起使用。您可以重新定义\sectionlinesformat以更改章节和小节标题的文本和数字的顺序:

\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{section}{\@hangfrom{\hskip #2}{#4 #3}}{%
    \ifstr{#1}{subsection}{\@hangfrom{\hskip #2}{#4 #3}}{%
      \@hangfrom{\hskip #2#3}{#4}}}%
}
\makeatother

要重新定义章节和小节标题中数字的格式,请使用

\renewcommand*\sectionformat{\thesection}
\renewcommand*\subsectionformat{\thesubsection)}
\renewcommand*{\thesubsection}{\alph{subsection}}

要更改或设置章节和小节标题的字体,请使用

\addtokomafont{disposition}{\rmfamily}
\setkomafont{section}{\Large}
\setkomafont{subsection}{\large}

要更改页眉或页脚中节文本和编号的顺序,请\sectionmark按照上述建议重新定义

\renewcommand*\sectionmark[1]{%
  \markright{#1 \ifnumbered{section}{\sectionmarkformat}{}}%
}
\renewcommand*\sectionmarkformat{\sectionformat}

最后一行确保页眉/页脚中的节号格式与节标题中的节号格式相同。

在此处输入图片描述

代码:

\documentclass[
  fontsize=10pt,
  headsepline,
  footsepline,
  abstract=on
]{scrartcl}[2015/10/03]
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[automark]{scrlayer-scrpage}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{section}{\@hangfrom{\hskip #2}{#4 #3}}{%
    \ifstr{#1}{subsection}{\@hangfrom{\hskip #2}{#4 #3}}{%
      \@hangfrom{\hskip #2#3}{#4}}}%
}
\makeatother
\renewcommand*\sectionformat{\thesection}
\renewcommand*\subsectionformat{\thesubsection)}
\renewcommand*{\thesubsection}{\alph{subsection}}

\addtokomafont{disposition}{\rmfamily}
\setkomafont{section}{\Large}
\setkomafont{subsection}{\large}

\renewcommand*\sectionmark[1]{%
  \markright{#1 \ifnumbered{section}{\sectionmarkformat}{}}%
}
\renewcommand*\sectionmarkformat{\sectionformat}

\clearpairofpagestyles
\ihead{Author}
\ohead{\today}

\ifoot{\rightmark}
\cfoot{Course xxx }
\ofoot{\pagemark}

\author{Chuck Norris}
\date{\today}
\title{xxx - Sheet 42}

\usepackage{lipsum}% dummy text
\begin{document}
\maketitle
\begin{abstract}
  \lipsum[1]
\end{abstract}
\clearpage
\section{Exercise}
\lipsum
\subsection{Part}
\lipsum[2]
\section{Exercise}
\subsection{Part}
\lipsum[3]
\subsection{Part}
\lipsum
\end{document}

要缩进整个小节部分,您可以使用addmargin

 \documentclass[
  fontsize=10pt,
  headsepline,
  footsepline,
  abstract=on
]{scrartcl}[2015/10/03]
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[automark]{scrlayer-scrpage}

\newcommand*\exercisepartindent{20pt}

\RedeclareSectionCommand[
  afterskip=.5\baselineskip
]{section}

\RedeclareSectionCommand[
  beforeskip=-.5\baselineskip,
  afterskip=1sp,
  indent=\exercisepartindent
]{subsection}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{section}{\@hangfrom{\hskip #2}{#4 #3}}{%
    \ifstr{#1}{subsection}{\@hangfrom{\hskip #2}{#4 #3}}{%
      \@hangfrom{\hskip #2#3}{#4}}}%
}
\makeatother
\renewcommand*\sectionformat{\thesection}
\renewcommand*\subsectionformat{\thesubsection)}
\renewcommand*{\thesubsection}{\alph{subsection}}

\addtokomafont{disposition}{\rmfamily}
\setkomafont{section}{\Large}
\setkomafont{subsection}{\large}

\automark{section}
\renewcommand*\sectionmark[1]{%
  \markright{#1 \ifnumbered{section}{\sectionmarkformat}{}}%
}
\renewcommand*\sectionmarkformat{\sectionformat}

\clearpairofpagestyles
\ihead{Author}
\ohead{\today}

\ifoot{\rightmark}
\cfoot{Course xxx }
\ofoot{\pagemark}

\author{Chuck Norris}
\date{\today}
\title{xxx - Sheet 42}

\newenvironment{exercisepart}{%
  \subsection{Part}
  \begin{addmargin}[\exercisepartindent]{0cm}%
}{%
  \end{addmargin}
}

\usepackage{lipsum}% dummy text
\begin{document}
\maketitle
\begin{abstract}
  \lipsum[1]
\end{abstract}
\clearpage
\section{Exercise}
\lipsum[1-2]
\begin{exercisepart}
  \lipsum[2]
\end{exercisepart}
\section{Exercise}
\begin{exercisepart}
  \lipsum[3]
\end{exercisepart}
\begin{exercisepart}
  \lipsum
\end{exercisepart}
\end{document}

结果

在此处输入图片描述


带有 KOMA-Script 版本早于 3.19(当前版本为 3.21)您必须使用titlesec来更改章节编号和文本的顺序。请注意,这是不推荐使用 3.19 或更新版本(往上看)。

\documentclass[
  fontsize=10pt,
  headsepline,
  footsepline,
  abstract=on
]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[automark]{scrlayer-scrpage}

\newcommand*\exercisepartindent{20pt}

\usepackage[explicit]{titlesec}
\titleformat{\section}{\usekomafont{disposition}\usekomafont{section}}{}{0pt}{#1\ \sectionformat}
\titleformat{\subsection}{\usekomafont{disposition}\usekomafont{section}}{}{0pt}{#1\ \subsectionformat}
\titlespacing*{\section}{0pt}{3.5ex plus 1ex minus .2ex}{.5\baselineskip}
\titlespacing*{\subsection}{\exercisepartindent}{.5\baselineskip}{0pt}


\def\sectionformat{\thesection}
\def\subsectionformat{\thesubsection}
\renewcommand*{\thesubsection}{\alph{subsection}}

\addtokomafont{disposition}{\rmfamily}
\setkomafont{section}{\Large}
\setkomafont{subsection}{\large}

\automark{section}
\renewcommand*\sectionmark[1]{%
  \markright{#1 \ifnumbered{section}{\sectionmarkformat}{}}%
}
\renewcommand*\sectionmarkformat{\sectionformat}

\clearpairofpagestyles
\ihead{Author}
\ohead{\today}

\ifoot{\rightmark}
\cfoot{Course xxx }
\ofoot{\pagemark}

\author{Chuck Norris}
\date{\today}
\title{xxx - Sheet 42}

\newenvironment{exercisepart}{%
  \subsection{Part}
  \begin{addmargin}[\exercisepartindent]{0cm}%
}{%
  \end{addmargin}
}

\usepackage{lipsum}% dummy text
\begin{document}
\maketitle
\begin{abstract}
  \lipsum[1]
\end{abstract}
\clearpage
\section{Exercise}
\lipsum[1-2]
\begin{exercisepart}
  \lipsum[2]
\end{exercisepart}
\section{Exercise}
\begin{exercisepart}
  \lipsum[3]
\end{exercisepart}
\begin{exercisepart}
  \lipsum
\end{exercisepart}
\end{document}

相关内容