0

I'm trying to build custom section headings, which have the text in the top of a coloured box of a specified height, with another coloured box of a specified height beneath. Much like this:

enter image description here

The closest I've got is the following:

enter image description here

from using this code

\documentclass[a4paper]{article}
\usepackage{xcolor,lipsum}
\usepackage{titlesec}

\titleformat{name=\section}[block]
  {\sffamily\LARGE\color{white}}
  {}
  {} % distance from left hand side
  {\colorsection}
\titlespacing*{\section}
    {} % distance from the left
    {\baselineskip}
    {\baselineskip}

\newcommand{\colorsection}[1]{%
    \colorbox{blue!70}
    {\parbox
       {\dimexpr\textwidth\fboxsep}
       {\thesection\ #1}}
    \colorbox{blue!50}
    {\parbox[][30pt][]
       {\pagewidth}
       {}}
}

\begin{document}

paragraph text 
\section{This is the title}
paragraph text
\end{document}

\parbox[][30pt][] appears to specify the height of the box, but setting this wipes the text out which then kills the width, which I would like to be full page. Is it parbox that I need to edit or something else?

0

Not quite sure why this works, but it does...

\documentclass[a4paper]{article}
\usepackage{xcolor,lipsum}
\usepackage{titlesec}

\titleformat{name=\section}[block]
  {\sffamily\LARGE\color{white}}
  {}
  {} % distance from left hand side
  {\colorsection}
\titlespacing*{\section}
    {} % distance from the left
    {\baselineskip}
    {\baselineskip}

\newcommand{\colorsection}[1]{%
    \colorbox{rgb:red,6;green,53;blue,50}
    {\parbox[][30pt][t]
       {\dimexpr\textwidth + 50pt \fboxsep}
       {\thesection\ #1}}
    \colorbox{rgb:red,00;green,160;blue,110}
    {\parbox[][100pt][t]
       {\dimexpr\textwidth + 50pt \fboxsep}
       {\ #}}
}

\begin{document}

paragraph text 
\section{This is the title}
paragraph text
\end{document}

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.