# Adding box filled with color and placing large text inside it

I am trying to prepare a class for my college magazine and articles. I would like to know how to place a black box on the top margin of the first page and write some huge text inside it in white color. Present style of the document looks like this,

% DOCUMENT LAYOUT
\documentclass[10pt, a4paper]{article}
\usepackage[left=5cm,right=2.5cm,top=5cm,bottom=3cm]{geometry}
\usepackage{fontspec}
\usepackage{marvosym}
\usepackage{wasysym}
% DOCUMENT LAYOUT
\setlength\parindent{0cm}
\usepackage[libertine={Ligatures=TeX,Numbers=OldStyle}]{libertineotf}
\setsansfont{Segoe UI}
% FONTS
\usepackage[usenames,dvipsnames]{color}
\usepackage{xunicode}
\usepackage{xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\usepackage{pgfplots}
\usepackage{xcolor}
\usepackage{eso-pic}

% ---- CUSTOM COMMANDS
\chardef\&="E050
\newcommand{\html}[1]{\href{#1}{\scriptsize\textsc{[html]}}}
\newcommand{\pdf}[1]{\href{#1}{\scriptsize\textsc{[pdf]}}}
\newcommand{\doi}[1]{\href{#1}{\scriptsize\textsc{[doi]}}}
% ---- MARGIN YEARS
\usepackage{marginnote}
\newcommand{\amper{}}{\chardef\amper="E0BD }
\newcommand{\sides}[1]{\marginnote{\color{MidnightBlue}\sffamily #1}}
%\newcommand{\years}[1]{\marginnote{\footnotesize #1}}
%\renewcommand*{\raggedleftmarginnote}{}
\setlength{\marginparsep}{0.5cm}
\reversemarginpar

\usepackage{sectsty}
\usepackage[normalem]{ulem}
\sectionfont{\mdseries\upshape\Large}
\subsectionfont{\mdseries\scshape\normalsize}
\subsubsectionfont{\mdseries\upshape\large}
\usepackage{lipsum}
\usepackage{tikz}
% PDF SETUP
pdftitle={Here there},
pdfauthor={My name},
pdfproducer={}
]{hyperref}
% DOCUMENT
\begin{document}
{\LARGE Effect of aspect ratio and others on others and ourselves}\\[3pt]
\textit{Me myself \& You}. Corr. author : \href{mailto:s.sssss@gmail.com}{\textit{s.sssss@gmail.com}}\\
\textit{Department of Mechanical Engineering.}\\[0.5cm]
{\large \bf Abstract}\\[4pt]
\lipsum[25]
{\section*{Introduction}}
\sides{I am hoping to create some proper paper using this template when i do my masters.}
\lipsum
\sides{How does a para look with this on sides. For a moment i thought it is gone}
\lipsum

%\vspace{1cm}
\vfill{}
%\hrulefill

\end{document}


Can some one suggest how to do this? I want something like the one on the right.

-
Are the positions of the text always equal? –  Marco Daniel Jun 4 '12 at 17:17
@MarcoDaniel Equal as in? I just want something similar to the photo shown where i can place a black box on top and white text. –  sgp Jun 6 '12 at 5:39

You have a problem with xcolor. You need to use the option dvipsnames to use the color MidnightBlue. You don't need to load color because xcolor loads color. pgfplots loads tikz and you need to load xcolor before pgfplots.

You need to compile twice the next code. I used tikz to place a ablack rectangle on the first page.

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
% DOCUMENT LAYOUT
\documentclass[10pt, a4paper]{article}
\usepackage[left=5cm,right=2.5cm,top=5cm,bottom=3cm]{geometry}
\usepackage{fontspec}
\usepackage{marvosym}
\usepackage{wasysym}
% DOCUMENT LAYOUT
\setlength\parindent{0cm}
\usepackage[libertine={Ligatures=TeX,Numbers=OldStyle}]{libertineotf}
%\setsansfont{Segoe UI}
\usepackage[dvipsnames]{xcolor}
% FONTS
\usepackage{xunicode}
\usepackage{xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\usepackage{pgfplots}

\usepackage{eso-pic}

% ---- CUSTOM COMMANDS
\chardef\&="E050
\newcommand{\html}[1]{\href{#1}{\scriptsize\textsc{[html]}}}
\newcommand{\pdf}[1]{\href{#1}{\scriptsize\textsc{[pdf]}}}
\newcommand{\doi}[1]{\href{#1}{\scriptsize\textsc{[doi]}}}
% ---- MARGIN YEARS
\usepackage{marginnote}
\newcommand{\amper{}}{\chardef\amper="E0BD }
\newcommand{\sides}[1]{\marginnote{\color{MidnightBlue}\sffamily #1}}
%\newcommand{\years}[1]{\marginnote{\footnotesize #1}}
%\renewcommand*{\raggedleftmarginnote}{}
\setlength{\marginparsep}{0.5cm}
\reversemarginpar

\usepackage{sectsty}
\usepackage[normalem]{ulem}
\sectionfont{\mdseries\upshape\Large}
\subsectionfont{\mdseries\scshape\normalsize}
\subsubsectionfont{\mdseries\upshape\large}
\usepackage{lipsum}
%\usepackage{tikz}
% PDF SETUP
pdftitle={Here there},
pdfauthor={My name},
pdfproducer={}
]{hyperref}
% DOCUMENT

\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,minimum width=21cm,minimum height=8cm,fill=black,text=white] (RB) at (current page.north west){\Huge TITLE};
\node[text=white,text width=4cm,anchor=north west] at ([shift={(3cm,2cm)}]RB.south west){\emph{Petit texte afin de tester la métode. Petit texte afin de tester la métode. Petit texte afin de tester la métode.}};
\end{tikzpicture}

\vspace*{10cm}
\lipsum[1]
\newpage
{\LARGE Effect of aspect ratio and others on others and ourselves}\\[3pt]
\textit{Me myself \& You}. Corr. author : \href{mailto:s.sssss@gmail.com}{\textit{s.sssss@gmail.com}}\\
\textit{Department of Mechanical Engineering.}\\[0.5cm]
{\large \bf Abstract}\\[4pt]
\lipsum[25]
{\section*{Introduction}}
\sides{I am hoping to create some proper paper using this template when i do my masters.}
\lipsum
\sides{How does a para look with this on sides. For a moment i thought it is gone}
\lipsum

%\vspace{1cm}
\vfill{}
%\hrulefill

\end{document}


-

You can use fancyhdr to place a \colorbox in the header:

\documentclass[10pt, a4paper]{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\fancypagestyle{unique}{%
\fancyfoot[C]{\thepage}%
\colorbox{black}{\parbox{\dimexpr\textwidth-2\fboxsep}{%
\color{white}\LARGE Effect of aspect ratio and others on others and ourselves}}%
}%
}
\begin{document}

\thispagestyle{unique}
\lipsum[1-10]

\end{document}


You can, of course, modify the unique page style to your liking. I've only duplicated the plain page style and added your required header.

Modifications to the header could include stretching the box to span outside the margin. Here's a quick view on the header changes to incorporate it:

\fancypagestyle{unique}{%
\fancyfoot[C]{\thepage}%
\makebox[\textwidth]{%
\colorbox{black}{\parbox{\dimexpr\textwidth+50pt-2\fboxsep}{%
\color{white}\LARGE Effect of aspect ratio and others on others and ourselves}}%
}}%
}


The above header change pushes the coloured box outward (left and right) by 25 points. It accomplishes this by placing a 50pt overset coloured box inside a centred \textwidth box. This avoids LaTeX complaining about an overfull \hbox spanning more than \textwidth.

-
Can you tell how to extend the black box even to the right and left margins at the top. –  sgp Jun 7 '12 at 0:54
@sgp: Added something to show how to extend the box into the margins. –  Werner Jun 7 '12 at 18:07

One:We can use the package tcolorbox by Thomas F. Sturm.

See

Make an Example and shaded box like in the book

Two: We can use the package contour

\documentclass{standalone}

\usepackage{tikz}
\usepackage[outline]{contour}
\contourlength{1.2pt}

\begin{document}

\begin{tikzpicture}[scale=2]

\draw [fill=black](0,0) rectangle (4.5,1);
\node at (0.75,0.5) {\contour{white}{\Large Text!}};
\node [fill=white,inner sep=1pt] at (2.25,0.5) {\Large Text!};
\node [fill=white,rounded corners=2pt,inner sep=1pt] at (3.75,0.5) {\Large Text!};

\end{tikzpicture}

\end{document}


Three: this may be useful

\documentclass{standalone}

\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[scale=2]
\node at (5,5) (p) {B};
\draw (p.south) -| ++(2mm,3mm) -| (p.north);
\end{tikzpicture}

\end{document}


-
I have updated the question with an example. Can you suggest now how to do it? –  sgp Jun 2 '12 at 14:59