форматирование заголовков/разделов/подразделов в статье

форматирование заголовков/разделов/подразделов в статье

Я борюсь с простой проблемой. Я использую класс KOMA

\documentclass[11pt]{scrartcl}%

Мне нужно отформатировать заголовки так, чтобы:

  • Заголовки разделовследует обозначать арабскими цифрами с точкой, например, 1., 2. и т. д.Текст выделен жирным шрифтом

введите описание изображения здесь

  • Подзаголовкиследует обозначать арабскими цифрами, за которыми следует точка, например, 1.1, 2.1 Текст не жирный

введите описание изображения здесь

  • Подподзаголовкиидентифицироваться арабскими цифрами с точкой, например, 1.1.1Текст курсивом.

введите описание изображения здесь

Для всех заголовков разделов все основные слова в названии должны быть написаны заглавными буквами, например: «Привет, Stackoverflow, это здорово».

Спасибо!!!!

решение1

Есть простой способ добавить точки на все уровни секционирования:

\usepackage[numbers=endperiod]{scrartcl}

Но на самом деле вы хотите, чтобы только разделы имели конечные точки, поэтому вам нужно сделать следующее:

\documentclass[]{scrartcl}

\renewcommand*{\sectionformat}{\thesection.\enskip}

Есть простой способ изменить шрифты:

\setkomafont{subsection}{\normalfont}
\setkomafont{subsubsection}{\normalfont\itshape}

Нет простого способа автоматически делать заглавные буквы. Но адаптируем ответ здесь:

можно использовать titlecapsпакет с scrartclклассом следующим образом. Если вы можете обойтись без автоматического заглавия букв (лично я бы просто сделал это сам), вы можете исключить всю эту часть кода. Вот полный пример.

Если вы действительно хотите это сделать, тоОтвет Швайнебакенемного проще, поскольку он изменяет код на один уровень абстракции выше, чем код, измененный мной.

\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

В адаптацииОтличный ответ Алансавы можете переопределить \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 не покажет заголовок таким, какой он есть на самом деле в заголовке. Поэтому вам придется вручную исправить заголовки, если вы хотите использовать nameref, как предложил @MichaelPalmer.

Результат:

введите описание изображения здесь

Связанный контент