[Tex/LaTex] Change section fonts

fontsmswordsectioningtitlesecxetex

I am trying to emulate MS Word 2010 functionality with LaTeX since I am fed up with word.

I am using TexShop, and I have been able to set the main font to Calibri through the use of XeTeX.

How do I set a different font/color/size for every type of section (section,subsection,subsubsection,…), without being limited to the standard LaTeX fonts? It would be nice to be able to choose any font from my system like XeTeX allows me to.

I have tried the package sectsty, but I was not able to figure out how to use Calibri with it.

Best Answer

The best way to have total control over the sectioning is the titlesec package. Here's a quick version of the standard MSWord sectioning for the first three levels. To control colours, you need the xcolor package.

If you are using different fonts for different section levels (not recommended) you should use fontspec's \newfontfamily command to define the font first, then use that in the redefinition of the title format, as in the subsubsection example.

This document can be compiled with either XeLaTeX or LuaLaTeX.

% Compile with XeLaTeX or LuaLaTeX
\documentclass[12pt]{article}
\usepackage[vmargin=1in,hmargin=1.25in]{geometry}
\usepackage{fontspec}
\usepackage{xcolor}
\usepackage{titlesec}
\defaultfontfeatures{Ligatures=TeX}
% Set sans serif font to Calibri
\setsansfont{Calibri}
% Set serifed font to Cambria
\setmainfont{Cambria}
% Define light and dark Microsoft blue colours
\definecolor{MSBlue}{rgb}{.204,.353,.541}
\definecolor{MSLightBlue}{rgb}{.31,.506,.741}
% Define a new fontfamily for the subsubsection font
% Don't use \fontspec directly to change the font
\newfontfamily\subsubsectionfont[Color=MSLightBlue]{Times New Roman}
% Set formats for each heading level
\titleformat*{\section}{\Large\bfseries\sffamily\color{MSBlue}}
\titleformat*{\subsection}{\large\bfseries\sffamily\color{MSLightBlue}}
\titleformat*{\subsubsection}{\itshape\subsubsectionfont}

\begin{document}
\section{A section}
This is some text.
\subsection{A subsection}
\subsubsection{A subsubsection}
\end{document}

output of code