# How to: print paragraph title centered, and on a shaded line across the page?

For a cheat sheet I am making I would like that \paragraph{title} does the following:

1. Centre the text 'title',
2. on a shaded (gray) line across the entire page ( column in my case ),
3. start the actual text in the paragraph without an indent.

Is this possible? If so, how should I set this up?

• \par{title} ????
– user31729
Oct 18 '15 at 10:02
• \paragraph or any name actually Oct 18 '15 at 10:05
• minimal example missing. A solution is dependent on the class in use. Oct 18 '15 at 10:20
• Since this is a cheat sheet, you could define your own command, which is much much simpler than changing a sectioning command. Much simpler. Oct 18 '15 at 11:46

Assuming that you are not using any KOMA class and your paragraph titles don't run in to more than one line, here is an example with titlesec package.

\documentclass[twocolumn]{article}
\usepackage{showframe}   %% for demo
\usepackage{lipsum}      %% for demo
\usepackage{titlesec}
\usepackage{xcolor}
\newcommand{\mytitle}[1]{\colorbox{gray!40}{\makebox[\dimexpr\columnwidth-2\fboxsep\relax]{\filcenter #1\strut}}}
\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{\mytitle}
\titlespacing*{\paragraph} {0pt}{3.25ex plus 1ex minus .2ex}{1em}
\begin{document}
\lipsum[1]
\paragraph{Title}
\lipsum[2]
\end{document}


• This is exactly what I was looking for. Thanks. Oct 18 '15 at 11:05

An alternative solution, assuming you are using a KOMA class.

I used section here, instead of paragraph.

\documentclass[10pt,landscape,DIV=18]{scrartcl}
\RedeclareSectionCommand[
beforeskip=-1ex,
afterskip=1ex,
]{section}
\setcounter{secnumdepth}{0}
\renewcommand{\raggedsection}{\centering}
\usepackage{blindtext}
\usepackage{multicol}
\usepackage{xcolor}
\colorlet{sectioncolor}{gray}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
\hspace*{#2}%
\colorbox{sectioncolor}{%
\parbox[t]{\dimexpr\linewidth-2\fboxsep-#2\relax}{%
\raggedsection\color{white}\@hangfrom{#3}{#4}%
}
}
}
\makeatother
\begin{document}
\begin{multicols}{6}
\section{ant}
\blindtext[2]
\section{bee}
\blindtext
\section{cat}
\blindtext
\section{Penguins and Dixie dancing ducks}
\blindtext
\end{multicols}
\end{document}

• You may note that this needs a recent KOMA version. Am I right?
– user11232
Oct 19 '15 at 2:40
• @HarishKumar Yes, it does. But i am not sure how recent. Oct 19 '15 at 8:07