Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Do you mean a header (as in header/footer) or are you referring to the title of a sectional unit, like \section? –  Gonzalo Medina Aug 17 '12 at 17:10
    
I was looking for a title of a sectional unit. Thanks. –  Sandeep Singh Aug 18 '12 at 2:55
add comment

1 Answer

up vote 7 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.