3

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?

4
  • \par{title} ????
    – user31729
    Oct 18, 2015 at 10:02
  • \paragraph or any name actually Oct 18, 2015 at 10:05
  • 1
    minimal example missing. A solution is dependent on the class in use.
    – Johannes_B
    Oct 18, 2015 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.
    – Johannes_B
    Oct 18, 2015 at 11:46

2 Answers 2

2

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}

enter image description here

1
  • This is exactly what I was looking for. Thanks. Oct 18, 2015 at 11:05
3

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

I used section here, instead of paragraph.

ndrookKomaSectionColor

\documentclass[10pt,landscape,DIV=18]{scrartcl}
\RedeclareSectionCommand[
    beforeskip=-1ex,
    afterskip=1ex,
]{section}
\addtokomafont{section}{\normalsize}
\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}
2
  • You may note that this needs a recent KOMA version. Am I right?
    – user11232
    Oct 19, 2015 at 2:40
  • @HarishKumar Yes, it does. But i am not sure how recent.
    – Johannes_B
    Oct 19, 2015 at 8:07

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.