Best ways to change section header colors in LaTeX

By default, section, subsection, and subsubsection headings in LaTeX appear in black.

However, in many cases, we may need to change the color of headers, especially when creating academic papers, presentations, reports, or other stylish documents.

A well-designed document with colored section headings can enhance readability and make it look more professional.

Changing section header colors using the xcolor package

One of the simplest ways to change the color of section headers in LaTeX is by using the xcolor package. This package provides easy color management and allows us to modify the color of the \section command.

Below is an example where we use \color{color-name} to apply color to headings.

\documentclass{article}
\usepackage{xcolor,lipsum}

\begin{document}

\section*{\textcolor{red}{Introduction}}
\lipsum[1][1-4]

\section*{\textcolor{blue}{Explanation}}
\lipsum[2][1-4]

\subsection*{\textcolor{green}{Results}}
\lipsum[3][1-4]

\end{document}

color title documents

In this example, we manually assign colors to different section titles using \textcolor{color-name}{text}. This method is straightforward and useful when you need different colors.

However, if you want all headers to have the same color automatically, then the sectsty package is a better choice.

Changing colors using the sectsty package

If you want to apply a uniform color to all section without manually changing each one, the sectsty package provides a more efficient solution.

\usepackage{sectsty}
\sectionfont{\color{red}} 
\subsectionfont{\color{blue}}

The following example demonstrates how to set red as the default color for all headings and blue for sub headings.

\documentclass{article}
\usepackage{xcolor,lipsum}
\usepackage{sectsty}

\sectionfont{\color{red}} 
\subsectionfont{\color{blue}}

\begin{document}

\section*{Introduction}
\lipsum[1][1-3]

\subsection*{Background}
\lipsum[2][1-4]

\end{document}

color title documents using sectsty package

Changing colors using the titlesec package

For advanced customization, including color, font size, bold style, and alignment, the titlesec package provides full control over section headers.

\documentclass{article}
\usepackage{xcolor,lipsum}
\usepackage{titlesec}

\titleformat{\section}
  {\color{red}\Huge\bfseries} 
  {}{0em}{}

\titleformat{\subsection}
  {\color{blue}\Large\bfseries}
  {}{0em}{}

\begin{document}

\section{Introduction}
\lipsum[1][1-3]

\subsection{Background}
\lipsum[1][1-4]

\end{document}

color title documents using titlesec package

Share tutorial

Leave a Comment

Your email address will not be published. Required fields are marked *