# Change color of numbers of sections

I want to change this box in which I have the section number to black, which I can do. But then the text is the same color and illegible. I need to make it white. I tried this but it didn't do anything.

\documentclass[12pt,letterpaper,twoside]{article}
\usepackage[margin=1in]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usepackage{lipsum}

\titleformat{\section}
{\normalfont\Large\bfseries}
{\llap{\colorbox{black}{\makebox[3em][r]  {\thesection}}\hspace{1em}}{\textbf{\textcolor{white}{\thesection}}}}
{-0.5em}{#1}
\renewcommand*{\thesection}{\Roman{section}}

\begin{document}
\section{Introduction}
\lipsum[1]

\end{document}


I think there is no need to print the section number twice. Hence I would change the third argument of the \titleformat command to

{\llap{\colorbox{black}{\makebox[3em][r]{\textcolor{white}{\thesection}}}\hspace{1em}}}


and use {0pt} as fourth argument to align the section title with the text body.

Code:

\documentclass[12pt,letterpaper,twoside]{article}
\usepackage[margin=1in]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usepackage{lipsum}

\renewcommand*{\thesection}{\Roman{section}}

\titleformat{\section}
{\normalfont\Large\bfseries}
{\llap{\colorbox{black}{\makebox[3em][r]{\textcolor{white}{\thesection}}}\hspace{1em}}}
{0pt}
{#1}

\begin{document}
\tableofcontents
\section{Introduction}
\lipsum[1]
\end{document}

• Yeah thanks. This works too. I guess the picture is a little different. The section doesn't end up coming twice. I was confusing the ToC with something else. – Zack Fair May 6 '15 at 13:42

Use this:

\renewcommand*{\thesection}{\textcolor{white}{\Roman{section}}}

\documentclass[12pt,letterpaper,twoside]{article}
\usepackage[margin=1in]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usepackage{lipsum}

\titleformat{\section}
{\normalfont\Large\bfseries}
{\llap{\colorbox{black}{\makebox[3em][r]  {\thesection}}\hspace{1em}}    {\textbf{\textcolor{white}{\thesection}}}}
{-0.5em}{#1}
\renewcommand*{\thesection}{\textcolor{white}{\Roman{section}}}

\begin{document}
\section{Introduction}
\lipsum[1]

\end{document}


• I believe, this would appear in the ToC as well, i.e. the \thesection would print white numbers (which means they aren't visible at all) – user31729 May 6 '15 at 12:02