[Tex/LaTex] Change the font of number in section

fontssectioning

I need to change the font of the number of the sections without changing the font of the name of section.

\documentclass[12pt,onecolumn]{article}
\sectionfont{\color{sec}\fontsize{16}{16}\FZzzh\selectfont}

The result is:

  1. section A

in the same font of FZzzh

The ideal output should be 1.(Arial) section A(FZzzh)

Best Answer

Here's a solution that doesn't make use of any particular LaTeX package. The code assumes that either XeLaTeX or LuaLaTeX is in use. I didn't make use of the \FZzzh instruction that's in your example code, though, as I don't have the font in question on my system.

The point of this method is that cross-references to section numbers, elsewhere in the document, will continue to be typeset in the ambient text font, rather than in the particular sans-serif font and color that's desired for the sectioning number in the section headers.

enter image description here

\documentclass{article}

\usepackage{fontspec}
\setsansfont{Arial}

\usepackage{xcolor}
\definecolor{sec}{RGB}{0,80,143}

\makeatletter  % see, e.g., p. 26 of "The LaTeX Companion"
  \def\@seccntformat#1{\@ifundefined{#1@cntformat}%
     {\csname the#1\endcsname\quad}%   default setting
     {\csname #1@cntformat\endcsname}% individual control
  }
  \def\section@cntformat{\color{sec}\textsf{\thesection}\quad}
\makeatother

\begin{document}
\section{In the beginning} \label{sec:beginning}

\section{Later on the same day}

As we showed in section \ref{sec:beginning}, \dots
\end{document}