我目前正在执行以下操作以便在 KOMA 文章中每个部分标题下方获得一条规则。
\documentclass[]{scrartcl}
% RULE BELOW SECTION TITLES
\makeatletter
\renewcommand{\sectionlinesformat}[4]{%
\ifstr{#1}{section}{%
\parbox[t]{\linewidth}{%
\raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
\kern-1.00\ht\strutbox\rule{\linewidth}{.8pt}%
}%
}{%
\@hangfrom{\hskip #2#3}{#4}}%
}
\makeatother
\begin{document}
\section{Whatever}
\subsection{Whatever else}
\end{document}
这是输出:
我曾尝试修改这种方法以在每个小节标题下方获得虚线规则,但没有成功。
您能帮我在每个小节标题下方生成一个虚线规则吗?
答案1
您可以使用包dashrule
:
\documentclass[]{scrartcl}
\usepackage{dashrule}
% RULE BELOW SECTION TITLES
\makeatletter
\renewcommand{\sectionlinesformat}[4]{%
\Ifstr{#1}{section}{%
\parbox[t]{\linewidth}{%
\raggedsection\@hangfrom{\hskip #2#3}{#4}\par%
\rule[1.5ex]{\linewidth}{.8pt}%
}%
}{%
\Ifstr{#1}{subsection}{%
\parbox[t]{\linewidth}{%
\raggedsection\@hangfrom{\hskip #2#3}{#4}\par
\hdashrule[1.5ex]{\linewidth}{.8pt}{.8pt}}}%
{\@hangfrom{\hskip #2#3}{#4}\par}%%
}%
}
\makeatother
\begin{document}
\section{Whatever}
\subsection{Whatever else}
\end{document}
我希望这就是你所要求的:
答案2
这里有一个与@lukeflo 类似的建议,但使用 LaTeX3\str_case:nn
而不是 KOMA-Script \ifstr
(已弃用)或\Ifstr
:
\documentclass[]{scrartcl}
\usepackage{blindtext}
\usepackage{dashrule}
%\usepackage{expl3}% should not be needed any longer, but if you are
% using a very old LaTeX installation, you can activate it
% RULE BELOW SECTION TITLES
\ExplSyntaxOn
\makeatletter
\renewcommand{\sectionlinesformat}[4]{
\str_case:nnF { #1 }
{
{ section }
{
\parbox[t]{\linewidth}{
\raggedsection\@hangfrom{\hskip #2#3}{#4}\par
\kern-1.00\ht\strutbox\rule{\linewidth}{.8pt}
}
}
{ subsection }
{
\parbox[t]{\linewidth}{
\raggedsection\@hangfrom{\hskip #2#3}{#4}\par
\hdashrule[2ex]{\linewidth}{.8pt}{.8pt}
}
}
}
{
\@hangfrom{\hskip #2#3}{#4}
}
}
\makeatother
\ExplSyntaxOff
\begin{document}
\section{Example of section}
\blindtext
\subsection{Example of subsection}
\blindtext
\subsubsection{Example of subsubsection}
\blindtext
\paragraph{Example of paragraph}
\blindtext
\subparagraph{Example of subparagraph}
\blindtext
\end{document}
看LaTeX3 接口有关 LaTeX3 及其类似功能的更多信息\str_case:nn
。