I want an underlining of my subsection titles - a horizontal line that extends the whole page width like a \hrule.
I tried the answer from this question which is to add these lines:
\titleformat{\subsection}
{\normalfont\Large\bfseries}{\thesection}{1em}{}[{\titlerule[0.8pt]}]
where I have changed \section to \subsection.
But this totally messes up all my subsection titles! I already have some color put on them and this is removed. Also, their subsection numbering (i.e. 5.1) disappears and only the section part of the numbering is displayed (i.e. 5).
How can I make this work? And is there a way to add this horizontal line below the title without overwriting existing formatting of the subsections?
My code structure
\documentclass[11pt,a4paper]{article}
\usepackage[utf8x]{inputenc} %Character set
\usepackage[explicit]{titlesec}
\usepackage{xcolor,lipsum}
...
%Setting subsection and subsubsection title color
\definecolor{red}{RGB}{163, 25, 25}
\subsectionfont{\color{red}}
\subsubsectionfont{\color{red}}
%Setting section title bg color
\definecolor{redbg}{RGB}{235, 214, 214}
\titleformat{\section}
{\normalfont\LARGE\bfseries}{}{0em}{\colorbox{redbg}{\parbox{\textwidth-2\fboxsep}{\textcolor{red}{\thesection\quad#1}}}}
%Underlining ruler for subsections
\titleformat{\subsection}
{\normalfont\Large\bfseries}{\thesection}{1em}{}[{\titlerule[0.8pt]}]
\begin{document}
\section
Text text text
\subsection
Text text text
\end{document}

titlesec, see http://tex.stackexchange.com/questions/233139/underline-subsection-heading/245037?s=7|4.6314#245037 – Jun 21 '15 at 18:47