0

I am trying to highlight background for entire section heading using

\documentclass{article}
\RequirePackage{titlesec}
\RequirePackage{charter}
\RequirePackage[hmargin=.3in, vmargin=0.1in]{geometry}
\RequirePackage{amsmath}
\RequirePackage{textcomp}
\RequirePackage{amssymb}
\RequirePackage{enumitem}
\RequirePackage{xcolor}
\RequirePackage{graphicx}
\RequirePackage{multicol}
\RequirePackage{array}
\titleformat{\section}{\large\scshape\raggedright}{}{0em}{\colorbox{gray}}[\titlerule]
\titlespacing{\section}{0em}{0.5em}{0.25em}
\begin{document}
\section{Lobo}
(Type your content here.)
\end{document}

but it only highlights the text. How do I highlight the entire line ?

1

Using the code from https://tex.stackexchange.com/a/40051/36296 gives

\documentclass{article}
\RequirePackage{titlesec}
\RequirePackage{charter}
\RequirePackage[hmargin=.3in, vmargin=0.1in]{geometry}
\RequirePackage{amsmath}
\RequirePackage{textcomp}
\RequirePackage{amssymb}
\RequirePackage{enumitem}
\RequirePackage{xcolor}
\RequirePackage{graphicx}
\RequirePackage{multicol}
\RequirePackage{array}
\titleformat{\section}{\large\scshape\raggedright}{}{0em}{\colorsection}[\titlerule]

\titleformat{name=\section,numberless}{\large\scshape\raggedright}{}{0em}{\colorsectionnonumber}[\titlerule]

\titlespacing{\section}{0em}{0.5em}{0.25em}

\newcommand{\colorsection}[1]{%
    \colorbox{gray}{\parbox{\dimexpr\textwidth-2\fboxsep}{\thesection\ #1}}}

\newcommand{\colorsectionnonumber}[1]{%
    \colorbox{gray}{\parbox{\dimexpr\textwidth-2\fboxsep}{#1}}}

\begin{document}
    \section{bla}

    abc

    \section*{Lobo}
    (Type your content here.)
\end{document}

enter image description here

| improve this answer | |

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