[Tex/LaTex] colorbox and text placement

colorhorizontal alignment

I was playing up with \colorbox for my resume and really loved the way I can create styling for the document.

Anyway I was trying to center align the text but failed to achieve it using the \centering command and if I use \begin{center} to allign the text, \colorbox width increase two fold which I don't want.

\newcommand \reshead [1]{\par \noindent \colorbox{black}{\begin{minipage} 
{\textwidth}{\color{white} \centering \bfseries {#1}} \hfill \end{minipage}}}

Apart from this issue, I wanted to my resume to look like this, the top line should be lesser in length compared to \colorbox

enter image description here

However with my code both are equal, is there a way I can stretch the \colorbox a bit more.? –

%% (c) Shashwat Pant
%% Resume - C.V of Shashwat Pant
%% September 17th 2012

\documentclass[letterpaper,12pt]{article}
%\usepackage[charter]{mathdesign}
% \usepackage{charter}
% \usepackage{mathpazo}
%\usepackage{kpfonts}
%\usepackage{geometry}
\usepackage{palatino}
\usepackage{url}
\usepackage[empty]{fullpage}
\usepackage{color}
%\definecolor{mygrey}{gray}{0.95}
%\usepackage{xcolor}

\newcommand \reshead [1]{\par \noindent \colorbox{black}{\begin{minipage}{\textwidth}{  \color{white} \centering \bfseries {#1}} \hfill \end{minipage}}}


\begin{document}

\begin{center}

\bfseries {\huge {Shashwat Pant}} \\
\bfseries E-Mail - shashwat.pant@gmail.com ~ Voice -    
\hrule \hrule
 \end{center}

\noindent Seeking a challenging career to gain experience in rich evolving computing in the areas of :  
\begin{itemize} 
    \item 
    \item Parallel and Vector computing (Open CL)

\end{itemize}   


\reshead{Professional Profile}



\end{document}

With my code the output look like this

enter image description here

Is there a way to stretch the colorbox and underlying text a bit towards left so that are not in same symmetry?

Best Answer

Here is an option that you can use:

enter image description here

\documentclass[letterpaper,12pt]{article}
\usepackage[empty]{fullpage}% http://ctan.org/pkg/fullpage
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{changepage}% http://ctan.org/pkg/changepage

\newcommand\reshead[1]{%
  \par\noindent%
  \colorbox{black}{\makebox[\dimexpr\linewidth-2\fboxrule-2\fboxsep][c]{\textcolor{white}{\bfseries #1}}}}

\begin{document}

\begin{adjustwidth}{2em}{2em}
  \begin{center}
    \bfseries
    {\huge Shashwat Pant} \\
    E-Mail - shashwat.pant@gmail.com ~ Voice - \\
  \end{center}

  \noindent\hspace*{-1em}\rule{\dimexpr\linewidth+2em}{2pt}

  \noindent Seeking a challenging career to gain experience in rich evolving computing in the areas of :  
  \begin{itemize} 
    \item 
    \item Parallel and Vector computing (Open CL)
  \end{itemize}
\end{adjustwidth}

\bigskip

\reshead{Professional Profile}

\end{document}​

Some things I've changed:

  • Instead of \hrule\hrule, use a specified rule width: \rule{\dimexpr\linewidth-2em}{2pt}. With the horizontal movement, this rule overhangs on both sides by 1em;
  • Added chngpage which provides the adjustwidth environment for modifying the margins locally; and
  • Used \makebox instead of minipage to specify the contents of your \reshead. Also updated the width to fix within the margins exactly (\linewidth-2\fboxrule-2\fboxsep).
Related Question