[Tex/LaTex] How to set different fonts for headings, text and captions

fontstitlesec

I want my

  1. Chapter names, section/subsection/… and other similar titles to be in gfsneohellenic
  2. Main text to be in libertine and libertinust1math.
  3. The captions of figures and tables will be some sans serif font as well, which I have not decided yet.

Using either

%\usepackage[default]{gfsneohellenic}
%\usepackage[LGR,T1]{fontenc}

OR

\usepackage[LGR, T1]{fontenc}
\usepackage{libertine}
\usepackage{libertinust1math}
\usepackage{titlesec}

sets the whole document to be in the respective fonts.

I am not being able to set the fonts specifically in titlesec, i.e. I am not being able to understand how to pass the specific fonts as parameters in the following –

\titleformat*{\section}{\Large\sffamily}
\titleformat*{\subsection}{\large\sffamily}
\titleformat*{\subsubsection}{\medium}

PS – I am using Overleaf.

Best Answer

When you use the default option with gfsneohellenic it sets both \rmdefault and \sfdefault to gfsneohellenic. If you leave out that option, you have finer control:

\documentclass{article}
\usepackage[LGR, T1]{fontenc}
\usepackage{libertine}
\usepackage{libertinust1math}
\usepackage{gfsneohellenic}
\renewcommand{\sfdefault}{neohellenic}

\usepackage{titlesec}
\titleformat*{\section}{\Large\sffamily}
\titleformat*{\subsection}{\large\sffamily}
\titleformat*{\subsubsection}{\normalsize\sffamily}

\usepackage{blindtext}
\begin{document}

\blinddocument
\end{document}

The particular fontname neohellenic is learned from gfsneohellenic.sty. Result:

enter image description here

Note that I have changed your definition for \subsubsection, since there is no \medium command in LaTeX.

Related Question