[Tex/LaTex] How to change the style of TITLE and SECTION in article class

sectioning

I want to change the style (fonts spacing etc.) of Title of paper and the sections of my paper written in article class. How can I change.

Best Answer

This redefines the \section command (using xparse facilities) and grabs the third argument (the section title), injects a font change command and restores the font afterwards. The ToC entry is still done in normal font (unless explicitly done in #2 or in the section title itself)

The kpfonts use the jkp basename for the font family, see the manual for the various options to use other names (and families).

The font change is done within the command \SectionHeadingFont and can be altered there. I chose the bx series, upright fontshape, but no additional scaling.

In my opinion the section number font should be changed to the same as the heading font.

Within the section title and the document title, I made explicit changes back to normal settings, in order to show the difference.

\documentclass{article}


\usepackage{xparse}
\usepackage{xpatch}
\usepackage{blindtext}



\let\LaTeXStandardSection\section%

\NewDocumentCommand{\SectionHeadingFont}{m}{%
  \fontfamily{jkpx}\fontseries{bx}\fontshape{n}\selectfont#1\normalfont%
}%

\NewDocumentCommand{\TitlePageFont}{}{%
  \fontfamily{jkpx}\fontseries{bx}\fontshape{n}\selectfont%
}%


\xpretocmd{\maketitle}{\TitlePageFont}{}{}
\xapptocmd{\maketitle}{\normalfont}{}




\RenewDocumentCommand{\section}{som}{%
  \let\LaTeXStandardTheSection\thesection% 
  % Redefine the section number formatting
  \renewcommand{\thesection}{\SectionHeadingFont{\arabic{section}}}% 
  \IfBooleanTF{#1}{%
    \LaTeXStandardSection*{#3}%
  }{%
    \IfValueTF{#2}{%
      \LaTeXStandardSection[#2]{\SectionHeadingFont{#3}}%
    }{%
      \LaTeXStandardSection[#3]{\SectionHeadingFont{#3}}%
    }%
  }%
  \renewcommand{\thesection}{\LaTeXStandardTheSection}%
}


\author{A.N. Author}
\title{How to use different fonts in \LaTeXe \normalfont\\ \bfseries How to use different fonts in \LaTeXe}


\begin{document}
\maketitle
\tableofcontents

% Compare in output
\section{First\normalfont\bfseries First}

\blindtext


\end{document}

enter image description here