7

I want to create a Fancy Title Header for an Article, like the one shown below:

enter image description here

Can someone please provide some hint on how to achieve this?

2
  • Do you mean a header (as in header/footer) or are you referring to the title of a sectional unit, like \section? Aug 17 '12 at 17:10
  • I was looking for a title of a sectional unit. Thanks. Aug 18 '12 at 2:55
8

Here's a solution using titleps:

\documentclass{article}
\usepackage{titleps}
\usepackage{xcolor}
\usepackage{lipsum}

\newcommand\HeaderTitle{Time For Action -- Embedding a picture within text}
\newpagestyle{myheader}
{
\sethead{}{\colorbox{black}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{%
  \strut\textcolor{white}{\sffamily\large\bfseries\HeaderTitle}}}}{}
}
\pagestyle{myheader}
\begin{document}

\lipsum[1-3]

\end{document}

enter image description here

The idea is to use a new page style using a \parbox of width equal to \textwidth inside a \colorbox.

Here's the same idea but using now fancyhdr:

\documentclass{article}
\usepackage{fancyhdr}
\usepackage{xcolor}
\usepackage{lipsum}

\newcommand\HeaderTitle{Time For Action -- Embedding a picture within text}

\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhf[C]{\colorbox{black}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{%
  \strut\textcolor{white}{\sffamily\large\bfseries\HeaderTitle}}}}
\setlength\headheight{18pt}
\pagestyle{fancy}

\begin{document}

\lipsum[1-3]

\end{document}

Now that I reread the question, I am not sure if a header (as in header/footer) was required or if the question is about the tiles for a sectional unit (\section, for example). My two examples above solve the first case; for the second case, here's a solution with titlesec (in both cases the idea for the solution reamains the same):

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{xcolor}
\usepackage{lipsum}

\titleformat{\section}
  {\normalfont\large\sffamily\bfseries}{}{0em}
  {\colorbox{black}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{%
    \textcolor{white}{\thesection\quad#1}}}}
\titleformat{name=\section,numberless}
  {\normalfont\large\sffamily\bfseries}{}{0em}
  {\colorbox{black}  {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{%
    \textcolor{white}{#1}}}}

\begin{document}

\lipsum[2]
\section*{Time For Action -- Embedding a picture within text}
\lipsum[2]

\end{document}

enter image description here

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.