0

So, i am struggling to change the font for title/section/subsection in latex.

Here is my code :

% !TEX TS?program = pdflatexmk

\documentclass[fontsize=12pt]{book}

\usepackage[T1]{fontenc}

\usepackage{amsmath}

\usepackage{mathpazo}

%changing font of section/chapter title
\usepackage{fontspec}
\usepackage{titlesec}
\newfontfamily\headingfont{Papyrus}
\titleformat{\chapter}{\LARGE\headingfont}
\titleformat{\section}{\LARGE\headingfont}
\titleformat{\subsection}{\Large\headingfont}
\titleformat{\subsubsection}{\large\headingfont}



\title{my report}
\author{user name}
\date


\linespread{1.5}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\maketitle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tableofcontents
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{introduction}
text : intro
\section{first section}
text :  section
\subsection{this subsection}
text :section
\subsubsection{this and that subsection}
text :subsub
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}

And this is the output: enter image description here The font is only implemented in the chapter and subsection. Not for others. And also the numbering is lost. For example, without titlesecand fontspec this is what it looks like. The chapter and subsection numbering is lost with that. I cant find the bug. (also kind of annoying to use fontspec as it could not find the default latex font, so had to copy paste the otf file in the working directory)

enter image description here

0

Do you want something like this?

sample

Here’s modified code

\documentclass[fontsize=12pt]{book}

\usepackage[T1]{fontenc}

\linespread{1.5}

\usepackage{amsmath}

\usepackage{mathpazo}

\usepackage{fontspec}

\newfontfamily\myheadingfont{Papyrus}

% changing font of section/chapter title

\usepackage{titlesec}

\setcounter{secnumdepth}{3}
\renewcommand{\thechapter}{\arabic{chapter}}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}
\renewcommand{\thesubsection}{(\arabic{chapter})\arabic{section}.\arabic{subsection}}
\renewcommand{\thesubsubsection}{\thesection.\arabic{subsection}.\arabic{subsubsection}}

\titleformat{\chapter}[hang]{\LARGE\myheadingfont}{\chaptertitlename~\thechapter.}{.4em}{\MakeUppercase}
\titleformat{\section}{\LARGE\myheadingfont}{Section~\thesection.}{.2em}{}
\titleformat{\subsection}{\Large\myheadingfont}{subsection~\thesubsection:}{.2em}{}
\titleformat{\subsubsection}{\large\myheadingfont}{\S~\thesubsubsection~}{.2em}{}

\begin{document}

\tableofcontents

\chapter{introduction}
text : intro
\section{first section}
text : section
\subsection{this subsection}
text : subsection
\subsubsection{this and that subsection}
text : subsub

\end{document}

\titleformat takes five non-optional parameters \titleformat{which}[shape]{format}{label}{hsep}{before-code}[after-code] (see http://ctan.altspu.ru/macros/latex/contrib/titlesec/titlesec.pdf). When you wish to change just format, then you would probably like its *-variant \titleformat*{which}{format}

For chapter, you may wish to place its text on other line, in such case use \titleformat{\chapter}[display] not [hang]

\setcounter{secnumdepth}{3} is that thing which adds numbering to “subsub”s too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.