Expanding on Zack's answer, this is my solution:
If you want the text left aligned
\newcommand{\mysubsection}[1]{
\setlength\fboxsep{4pt} %% spacing around box contents
\subsection*{\colorbox{bgcol}{\makebox[\textwidth][l]{\color{textcol}#1\hfill}}}
}
or if you want it centred
\newcommand{\mysubsection}[1]{
\setlength\fboxsep{4pt} %% spacing around box contents
\subsection*{\colorbox{bgcol}{\makebox[\textwidth]{\color{textcol}#1}}}
}
You can drop the local declaration of \setlength\fboxsep if you are using a global setting.
Obviously bgcol and textcol need to be defined earlier in the document preamble.
If are in the multicols environment you can use \textwidth or \columnwidth, or a relative amount of either these, depending on how you have things laid out and how you want them to look.
I am using multicols with the text spanning 100% of the column. But found that using either \textwidth or \columnwidth the headings overhang to the right side compared with the width of the text body underneath, so to correct this I actually ended up using:
\newcommand{\mysubsection}[1]{
\setlength\fboxsep{4pt} %% spacing around box contents
\subsection*{\colorbox{bgcol}{\makebox[0.97\textwidth]{\color{textcol}#1}}}
}
Caution: I am getting error messages from "Overfull \hbox" using this code. I don't know how to resolve this, but the output is working fine so it is not an issue for me. On a different program or build this may cause you problems!