formato de títulos/secciones/subsecciones en el artículo

formato de títulos/secciones/subsecciones en el artículo

Estoy luchando con un problema simple. Estoy usando la clase KOMA.

\documentclass[11pt]{scrartcl}%

Necesito formatear los encabezados de mis títulos para que:

  • Encabezados de seccióndebe identificarse mediante números arábigos seguidos de un punto, por ejemplo, 1., 2., etc.Texto en negrita

ingrese la descripción de la imagen aquí

  • Subtítulosdebe identificarse con números arábigos seguidos de un punto, por ejemplo, 1.1, 2.1 Texto no negrita

ingrese la descripción de la imagen aquí

  • Subsubtítulosidentificarse mediante números arábigos seguidos de un punto. por ejemplo 1.1.1Texto en cursiva.

ingrese la descripción de la imagen aquí

Para todos los títulos de las secciones, todas las palabras principales del título deben estar en mayúscula, por ejemplo, "Hola Stackoverflow, esto es genial".

¡¡¡¡Gracias!!!!

Respuesta1

Hay una forma sencilla de agregar puntos a todos los niveles de sección:

\usepackage[numbers=endperiod]{scrartcl}

Pero, de hecho, desea que sólo las secciones tengan puntos finales, por lo que debe hacer lo siguiente:

\documentclass[]{scrartcl}

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

Hay una forma sencilla de cambiar las fuentes:

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

No existe una forma sencilla de cambiar el título entre mayúsculas y minúsculas automáticamente. Pero adaptando la respuesta aquí:

Es posible utilizar el titlecapspaquete con la scrartclclase de la siguiente manera. Si puede vivir sin título automático (yo personalmente lo haría usted mismo), puede eliminar toda esta parte del código. Aquí está el ejemplo completo.

Si quieres hacer esto, entoncesLa respuesta de Schweinebackees un poco más simple ya que modifica el código un nivel de abstracción superior al código que modifiqué.

\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}

salida de código

Respuesta2

En adaptación deLa gran respuesta de Alans.podrías redefinir \sectionlinesformaten lugar de \sectiony hacer que los encabezados estén automáticamente en mayúsculas \subsection:\subsubsection

\let\orig@sectionlinesformat\sectionlinesformat
\renewcommand*{\sectionlinesformat}[4]{%
  \orig@sectionlinesformat{#1}{#2}{#3}{\titlecap{#4}}%
}%

Para cambiar el caso de las entradas de la tabla de contenido, puede redefinir \addtocentrydefault:

\let\orig@addtocentrydefault\addtocentrydefault
\renewcommand*{\addtocentrydefault}[3]{%
  \orig@addtocentrydefault{#1}{#2}{\titlecap{#3}}%
}

Y para cambiar el caso del cabezal en ejecución, podría redefinir \MakeMarkcase:

\let\MakeMarkcase\titlecap

MWE:

\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}

Pero si te gustan los trucos sucios, también puedes hacer:

\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}

Ambas sugerencias dan como resultado:

ingrese la descripción de la imagen aquí

El código del eslogan es para \paragraphy \subparagraph.

Respuesta3

Última edición(Tuve que editar la respuesta porque había demasiados votos positivos que realmente no merecía)

\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}

Resultado: ingrese la descripción de la imagen aquí

Editar: Como @AlanMunn mencionó, mi método no se sugiere con esta clase de documento y voy a actualizar la respuesta para incluir esta clase de documento... Si alguien respondió a esta pregunta usando otra clase de documento, probablemente pueda usar este método como uno fácil.

Aquí hay una manera fácil para todo lo que necesitas... Simplemente no olvides excluir las ecuaciones o las palabras que no deseas poner en mayúscula de la función de capitalizar como lo hice con el comando MFUnocap... de lo contrario tendrás errores.

\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}

Observe también que el posible uso de nameref no mostrará el título como realmente está en el título. Por lo tanto, debe corregir manualmente los títulos si desea utilizar nameref como sugirió @MichaelPalmer.

Resultado:

ingrese la descripción de la imagen aquí

información relacionada