答案1
有一个简单的方法可以将点添加到所有分区级别:
\usepackage[numbers=endperiod]{scrartcl}
但实际上您只希望各部分有最后的点,因此您需要执行以下操作:
\documentclass[]{scrartcl}
\renewcommand*{\sectionformat}{\thesection.\enskip}
有一种简单的方法可以更改字体:
\setkomafont{subsection}{\normalfont}
\setkomafont{subsubsection}{\normalfont\itshape}
没有简单的方法可以自动执行标题大小写。但在这里调整答案:
可以按照以下方式titlecaps
将包与scrartcl
类一起使用。如果您可以忍受没有自动标题大小写(我个人会自己做),您可以消除所有这部分代码。这是完整的示例。
如果你确实想这样做,那么Schweinebacke 的回答稍微简单一些,因为它修改的代码比我修改的代码高一个抽象级别。
\documentclass[]{scrartcl}
\setkomafont{subsection}{\normalfont}
\setkomafont{subsubsection}{\normalfont\itshape}
\renewcommand*{\sectionformat}{\thesection.\enskip}
% The rest of this preamble code is only needed for automatic title casing
\usepackage{titlecaps}
% this is a space separated list of words that should be lowercase
% since you have to add to this list manually, title casing is not truly automatic
\Addlcwords{a an the that to this is are and with}
\makeatletter
% adapted from https://tex.stackexchange.com/a/33215/
% ---- only needed for automatic title case ----
\let\scr@section\section
\let\scr@subsection\subsection
\let\scr@subsubsection\subsubsection
\def\section{\@ifstar\cased@sections\cased@section}
\def\subsection{\@ifstar\cased@subsections\cased@subsection}
\def\subsubsection{\@ifstar\cased@subsubsections\cased@subsubsection}
\def\cased@sections#1{\scr@section*{\titlecap{#1}}}
\def\cased@subsections#1{\scr@subsection*{\titlecap{#1}}}
\def\cased@subsubsections#1{\scr@subsubsection*{\titlecap{#1}}}
\def\cased@section{\@dblarg{\cased@section@}}
\def\cased@subsection{\@dblarg{\cased@subsection@}}
\def\cased@subsubsection{\@dblarg{\cased@subsubsection@}}
\def\cased@section@[#1]#2{%
\scr@section[\titlecap{#1}]{\titlecap{#2}}}
\def\cased@subsection@[#1]#2{%
\scr@subsection[\titlecap{#1}]{\titlecap{#2}}}
\def\cased@subsubsection@[#1]#2{%
\scr@subsubsection[\titlecap{#1}]{\titlecap{#2}}}
\makeatother
% ---- only needed for automatic titlecase ----
\begin{document}
\section{A section with a word that should use uppercase}
\subsection{This is a subsection with most words uppercase}
\subsubsection{This is a subsubsection}
\end{document}
答案2
改编Alans 的精彩回答您可以重新定义\sectionlinesformat
而不是\section
,\subsection
并使\subsubsection
标题自动大写:
\let\orig@sectionlinesformat\sectionlinesformat
\renewcommand*{\sectionlinesformat}[4]{%
\orig@sectionlinesformat{#1}{#2}{#3}{\titlecap{#4}}%
}%
要更改目录中条目的大小写,可以重新定义\addtocentrydefault
:
\let\orig@addtocentrydefault\addtocentrydefault
\renewcommand*{\addtocentrydefault}[3]{%
\orig@addtocentrydefault{#1}{#2}{\titlecap{#3}}%
}
要改变页眉的大小写,你可以重新定义\MakeMarkcase
:
\let\MakeMarkcase\titlecap
梅威瑟:
\documentclass[]{scrartcl}
\setkomafont{subsection}{\normalfont}
\setkomafont{subsubsection}{\normalfont\itshape}
\renewcommand*{\sectionformat}{\thesection.\enskip}
\renewcommand*{\sectionmarkformat}{\sectionformat}% also for running head
% The rest of this preamble code is only needed for automatic title casing
\usepackage{titlecaps}
% this is a space separated list of words that should be lowercase
% since you have to add to this list manually, title casing is not truly automatic
\Addlcwords{a an the that to this is are and with}
\makeatletter
\let\orig@sectionlinesformat\sectionlinesformat
\renewcommand*{\sectionlinesformat}[4]{%
\orig@sectionlinesformat{#1}{#2}{#3}{\titlecap{#4}}%
}%
\let\orig@addtocentrydefault\addtocentrydefault
\renewcommand*{\addtocentrydefault}[3]{%
\orig@addtocentrydefault{#1}{#2}{\titlecap{#3}}%
}
% and if you also want the case change for \paragraph and \subparagraph:
\let\orig@sectioncatchphraseformat\sectioncatchphraseformat
\renewcommand*{\sectioncatchphraseformat}[4]{%
\orig@sectioncatchphraseformat{#1}{#2}{#3}{\titlecap{#4}}%
}
\makeatother
\let\MakeMarkcase\titlecap
% ---- only needed for automatic titlecase ----
\pagestyle{headings}% to show the running head
\begin{document}
\tableofcontents
\section{A section with a word that should use uppercase}
\subsection{This is a subsection with most words uppercase}
\subsubsection{This is a subsubsection}
\newpage
Empty page
\end{document}
但如果你喜欢卑鄙的伎俩,你也可以这样做:
\documentclass[]{scrartcl}
\setkomafont{subsection}{\normalfont}
\setkomafont{subsubsection}{\normalfont\itshape}
\renewcommand*{\sectionformat}{\thesection.\enskip}
\renewcommand*{\sectionmarkformat}{\sectionformat}% also for running head
% The rest of this preamble code is only needed for automatic title casing
\usepackage{titlecaps}
% this is a space separated list of words that should be lowercase
% since you have to add to this list manually, title casing is not truly automatic
\Addlcwords{a an the that to this is are and with}
\makeatletter
\let\orig@sectionlinesformat\sectionlinesformat
\renewcommand*{\sectionlinesformat}[4]{%
\orig@sectionlinesformat{#1}{#2}{#3}{\titlecap{#4}}%
\expandafter\gdef\expandafter\@currenttocentry\expandafter{%
\expandafter\titlecap\expandafter{\@currenttocentry}%
}%
\expandafter\gdef\expandafter\@currentheadentry\expandafter{%
\expandafter\titlecap\expandafter{\@currentheadentry}%
}%
}%
\let\orig@sectioncatchphraseformat\sectioncatchphraseformat
\renewcommand*{\sectioncatchphraseformat}[4]{%
\orig@sectioncatchphraseformat{#1}{#2}{#3}{\titlecap{#4}}%
\expandafter\gdef\expandafter\@currentheadentry\expandafter{%
\expandafter\titlecap\expandafter{\@currentheadentry}%
}%
}
\makeatother
% ---- only needed for automatic titlecase ----
\pagestyle{headings}% to show the running head
\begin{document}
\tableofcontents
\section{A section with a word that should use uppercase}
\subsection{This is a subsection with most words uppercase}
\subsubsection{This is a subsubsection}
\newpage
Empty page
\end{document}
这两个建议的结果是:
标语代码为\paragraph
和\subparagraph
。
答案3
最后编辑(由于太多赞同票,我不得不编辑答案,因为它并不值得)
\documentclass[11pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{nameref}
\usepackage{mfirstuc}
\MFUnocap{$f(x)=2\cdot x$}
\renewcommand{\sectionformat}{}
\renewcommand{\subsectionformat}{}
\renewcommand{\subsubsectionformat}{}
\renewcommand*\sectionformat{\normalfont\bfseries\Large}
\renewcommand*\subsectionformat{\normalfont\mdseries\rmfamily\large}
\renewcommand*\subsubsectionformat{\normalfont\itshape\large}
\let\oldsection\section
\makeatletter
\def\section{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\setkomafont{section}{\sectionformat}%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}
\def\@StarredWith[#1]#2{%
\oldsection*{\capitalisewords{#2}}%
}
\def\@StarredWithout#1{%% This would be simpler if your table of contents is not a section...
\ifnum\pdfstrcmp{#1}{\contentsname}=0%
\renewcommand{\sectionformat}{}%
\setkomafont{section}{\sectionformat}%
\oldsection*{\contentsname}%
\else%
\oldsection*{\capitalisewords{#1}}%
\fi%
}
\def\@nonStarred{%
\setkomafont{section}{\sectionformat\thesection.\space}%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\oldsection[#1]{\capitalisewords{#2}}%
}
\def\@nonStarredWithout#1{%
\oldsection{\capitalisewords{#1}}%
}
\makeatother
\let\oldsubsection\subsection
\makeatletter
\def\subsection{%
\@ifstar{\@Starredss}{\@nonStarredss}%
}
\def\@Starredss{%
\setkomafont{subsection}{\subsectionformat}%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWithss}%
{\@StarredWithout}%
}
\def\@StarredWithss[#1]#2{%
\oldsubsection*{\capitalisewords{#2}}%
}
\def\@StarredWithoutss#1{%% This would be simpler if your table of contents is not a subsection...
\ifnum\pdfstrcmp{#1}{\contentsname}=0%
\renewcommand{\sectionformat}{}%
\setkomafont{subsection}{\sectionformat}%
\oldsubsection*{\contentsname}%
\else%
\oldsubsection*{\capitalisewords{#1}}%
\fi%
}
\def\@nonStarredss{%
\setkomafont{subsection}{\subsectionformat\thesubsection\space}%
\@ifnextchar[%
{\@nonStarredWithss}%
{\@nonStarredWithoutss}%
}
\def\@nonStarredWithss[#1]#2{%
\oldsubsection[#1]{\capitalisewords{#2}}%
}
\def\@nonStarredWithoutss#1{%
\oldsubsection{\capitalisewords{#1}}%
}
\makeatother
\let\oldsubsubsection\subsubsection
\makeatletter
\def\subsubsection{%
\@ifstar{\@Starredsss}{\@nonStarredsss}%
}
\def\@Starredsss{%
\setkomafont{subsubsection}{\subsubsectionformat}%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWithsss}%
{\@StarredWithout}%
}
\def\@StarredWithsss[#1]#2{%
\oldsubsubsection*{\capitalisewords{#2}}%
}
\def\@StarredWithoutsss#1{%% This would be simpler if your table of contents is not a subsection...
\ifnum\pdfstrcmp{#1}{\contentsname}=0%
\renewcommand{\sectionformat}{}%
\setkomafont{subsection}{\sectionformat}%
\oldsubsubsection*{\contentsname}%
\else%
\oldsubsubsection*{\capitalisewords{#1}}%
\fi%
}
\def\@nonStarredsss{%
\setkomafont{subsubsection}{\subsubsectionformat\thesubsubsection\space}%
\@ifnextchar[%
{\@nonStarredWithsss}%
{\@nonStarredWithoutsss}%
}
\def\@nonStarredWithsss[#1]#2{%
\oldsubsubsection[#1]{\capitalisewords{#2}}%
}
\def\@nonStarredWithoutsss#1{%
\oldsubsubsection{\capitalisewords{#1}}%
}
\makeatother
\begin{document}
\tableofcontents
\section{test section 1 with text of non-capitalized first word}
That was the first test section and here comes the second named ``\nameref{sec:secd}''
\section{the second section with equation $f(x)=2\cdot x$}\label{sec:secd}
\section*{a section with star}
\subsection{the first subsection}
And we can use very simple the nameref like this: ``\nameref{subsub}''
\subsubsection{a subsubsection}\label{subsub}
\end{document}
编辑:正如@AlanMunn 提到的,我的方法不建议使用此文档类,我将更新答案以包含此文档类...如果有人使用其他文档类到达这个问题,可能可以将此方法用作一种简单的方法。
这是满足您所有需求的简单方法...只是不要忘记从大写函数中排除您不想大写的方程式或单词,就像我对命令 MFUnocap 所做的那样...否则您将遇到错误。
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{nameref}
\usepackage[explicit]{titlesec}
\usepackage{mfirstuc}
\MFUnocap{$f(x)=2\cdot x$}
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection.}{1em}{\capitalisewords{#1}}
\titleformat{\subsection}
{\normalfont\large}{\thesubsection}{1em}{\capitalisewords{#1}}
\titleformat{\subsubsection}
{\normalfont\large\itshape}{\thesubsubsection}{1em}{\capitalisewords{#1}}
\begin{document}
\section{Test section 1 with text of non-capitalized first word}
That was the first test section and here comes the second named ``\nameref{sec:second}''
\section{the second section with equation $f(x)=2\cdot x$}\label{sec:second}
\subsection{the first subsection}
\subsubsection{a subsubsection}
\end{document}
还要注意,nameref 的可能用法不会显示标题中的真实内容。因此,如果您想按照@MichaelPalmer 的建议使用 nameref,则必须手动修复标题。
结果: