1

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}
\linespread{1.3}

\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}
2

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.

enter image description here

Code:

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

\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}
| improve this answer | |
  • 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
0

Use this:

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

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

\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}

enter image description here

| improve this answer | |
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.