# How to edit the length of a color box?

I've typed my Resume and Im using a color box, with a line underneath it. However the grey colored box doesn't reach the full length of the page width.

\documentclass[letterpaper,11pt]{article}
\usepackage[left=0.9in, right=0.8in]{geometry}
\pagestyle{empty}
\raggedright
\def\bull{\vrule height 0.8ex width .7ex depth -.1ex }

\newcommand{\lineunder}{\vspace*{-8pt} \\ \hspace*{-18pt} \hrulefill \\} %command for the Line to be drawn

\usepackage[usenames,dvipsnames]{color}
\definecolor{mygrey}{gray}{.90}
\newcommand{\headergrey}[1]{\hspace*{-18pt} \colorbox{mygrey}
{\begin{minipage}
{\textwidth}{\textsc{#1}}
\end{minipage}}\lineunder}

\begin{document}

\headergrey{Objective}
Seeking a Full Time position in the area of Blah blah blah Blah
\end{document}


See the image attached so as to what i mean please.

-
In general I recommend my adjustbox package to easily create and modify such boxes. However, it is not yet possible to draw a line only on one side of the box. –  Martin Scharrer May 22 '13 at 10:22

## 2 Answers

You should not ignore LaTeX warnings about overfull boxes. The basic problem in your original is that the box constructed does not fit on the page. The inner minipage is \textwidth wide but \colorbox, like \fbox adds padding around the box of length \fboxsep so the box was 2\fboxsep (6pt) too wide and then it was at the start of a paragraph so further indented by the paragraph indent, sticking it into the left margin.

\documentclass[letterpaper,11pt]{article}
\usepackage[left=0.9in, right=0.8in]{geometry}
\pagestyle{empty}
\raggedright
\def\bull{\vrule height 0.8ex width .7ex depth -.1ex }

\usepackage[usenames,dvipsnames]{color}
\definecolor{mygrey}{gray}{.90}
\newcommand{\headergrey}[1]{\par\noindent{\setlength\fboxsep{0pt}\hspace*{-18pt}\colorbox{mygrey}
{\begin{minipage}{\dimexpr\textwidth-2\fboxsep+18pt\relax}
\vspace{2pt}%
\textsc{\strut\hspace{3pt}#1}\par
\hrule
\end{minipage}}\par\smallskip}}

\begin{document}

\headergrey{Objective}
Seeking a Full Time position in the area of Blah blah blah Blah
\end{document}

-
David, The grey box now covers that gap, however there is a huge separation after the text like this (imgur.com/0Ax0Tv8). I tried to play around with the \par before \hrulefill and replace it with a \\ and few other things, however no change! –  Karan May 23 '13 at 9:11
@Karan sorry I'd copied \hrulefill from the question but used it as if it was \hrule so you got an extra paragraph, updated with image. –  David Carlisle May 23 '13 at 13:37
it works, however, as you see, the Header line in my original starts a little indented, so how to shift it towards the left (just like the original)? –  Karan May 24 '13 at 8:11
@Karan updated with header outdented into margin –  David Carlisle May 24 '13 at 8:21

Among other possible methods, you can set the box in a tabular instead. It gives you better control over the entire heading construct:

\documentclass[letterpaper,11pt]{article}
\usepackage[left=0.9in, right=0.8in]{geometry}% http://ctan.org/pkg/geometry
\usepackage{colortbl}% http://ctan.org/pkg/colortbl

\definecolor{mygrey}{gray}{.90}
\newcommand{\headergrey}[1]{%
\noindent\hspace*{-15pt}%
\tabular{p{\dimexpr\linewidth-2\tabcolsep+15pt}}\cellcolor{mygrey}\textsc{#1}\\\hline\endtabular%
\par\nobreak}%

\pagestyle{empty}\raggedright
\begin{document}

\headergrey{Objective}
Seeking a Full Time position in the area of Blah blah blah Blah

\end{document}


The horizontal negative indent (hang) is 15pt. Also, if required, you can increase the vertical gap between the heading and subsequent text.

-
It gives me an error: ! Undefined control sequence. \headergrey ...dth -2\tabcolsep +15pt}}\cellcolor {mygrey}\textsc {#1}\\\hli... l.26 \headergrey{Objective} –  Karan May 22 '13 at 7:34
@Karan: I can't diagnose the problem with only this. You should post your full code at PasteBin, or include it in an edit to your post. –  Werner May 22 '13 at 14:28
Hi Werner, Thank you for that advice. Here you go, its on Pastebin (pastebin.com/M8LkbWwN#) Also, I stuck with \usepackage[usenames,dvipsnames]{color} instead of your suggestion \usepackage{colortbl} But i dont think that should create a big problem right? –  Karan May 23 '13 at 8:47
Werner, I also tried this where i wrote \begin{tabular} and \end{tabular} - still gives an error. (pastebin.com/gMB2FZSs) –  Karan May 23 '13 at 9:09
@Karan: colortbl provides \cellcolor, so you need it in order for my solution to work. Note that colortbl loads color so you only have to load colortbl with the same options you would normally load color with. –  Werner May 23 '13 at 13:07