2

enter image description here

The image included above is what I want to replicate - I want the name to appear on the top left, and the address/email-id to appear on the top right, and I want both of them to be aligned with the body of the text.

The following is my attempt at it (the blah blah text is there to demonstrate the alignment problem) -

\documentclass[a4paper,10pt]{article}

\usepackage{a4wide}
\usepackage{color}
\usepackage{xcolor,mdframed}

\usepackage[hmargin=1cm,vmargin=1.5cm]{geometry}

\begin{document}

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill} } l r }
  \huge{\textbf{John Doe}} & Qtr D/40, Unit 12, Upper Kolkata\\
                           & (011) 2040-3455 [email protected]\\
\end{tabular*}

\bigskip

\begin{minipage}[c]{0.3\linewidth}
\begin{mdframed}[backgroundcolor=gray!10]
\bigskip
blah blah blah blah blah blah blah blah blah \
blah blah blah blah blah blah blah blah blah blah blah blah \
\bigskip
\end{mdframed}
\end{minipage} 
\begin{minipage}[c]{0.2\linewidth}

\end{minipage} 
\begin{minipage}[c]{0.6\linewidth}
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah      
blah blah blah
\end{minipage} 

\end{document}

And what I get out of it is this -

enter image description here

As can be seen, the address/email-id text on the right overflows and exceed the text margin for the rest of the document.

How do I fix it? Also, is it a good idea to use tables for this kind of layout? What is a good alternative?

Thanks in advance.

4
  • you're specifying \textwidth for the name line at the top, and everything else uses \linewidth. one would think the same dimension register should be used for both. Apr 9, 2013 at 13:53
  • That \textwidth is actually a leftover from my experiments, sorry about that. I tried \linewidth too, but it didn't work.
    – Soumendra
    Apr 9, 2013 at 14:04
  • It seems that the problem is with the minipage. When I put more text below it, it gets aligned with the address/email-id, and not the minipages. So I guess we have to fix the alignment of the minipages. Will I be correct to assume that the geometry package doesn't affect the alignment of minipages?
    – Soumendra
    Apr 9, 2013 at 14:08
  • 2
    a table gets set like a big letter and that is the start of a paragraph so indented by \parindent put \noindent before it Apr 9, 2013 at 14:09

1 Answer 1

2

I'd suggest avoiding explicit mark up, which is tedious and error prone.

My realization of the header uses tabular* with two nested tabular environment that ensure vertical centering as in the original.

For the personal data, I suggest a data environment that contains both the left part and the right part, each prefixed by the corresponding commands. The width of the right part is computed once and for all at the beginning of the document and the width of the left part is computed accordingly, leaving some predetermined space (here two ems).

\documentclass[a4paper,10pt]{article}
\usepackage[hmargin=1cm,vmargin=1.5cm,showframe]{geometry}

\usepackage{color}
\usepackage{xcolor,mdframed}

\newsavebox{\databox}
\newlength{\datawidth}
\AtBeginDocument{
  \sbox{\databox}{%
    \leftpart Mock text
    \end{mdframed}\end{minipage}}
  \setlength{\datawidth}{\wd\databox}
}
\newenvironment{data}
 {\noindent\ignorespaces}
 {\end{minipage}\par}
\newcommand{\leftpart}{%
  \begin{minipage}{.3\textwidth}
  \begin{mdframed}[
    backgroundcolor=gray!10,
    innertopmargin=\bigskipamount,
    innerbottommargin=\bigskipamount]}
\newcommand{\rightpart}{%
  \end{mdframed}
  \end{minipage}\hfill
  \begin{minipage}{\dimexpr\textwidth-2\tabcolsep-\datawidth}}


\begin{document}

\noindent%%% remember this
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill} } l r@{}}
\begin{tabular}{@{}l@{}}
  \huge\bfseries John Doe
\end{tabular}
&
\begin{tabular}{@{}l@{}}
  Qtr D/40, Unit 12, Upper Kolkata\\
  (011) 2040-3455 [email protected]
\end{tabular}
\end{tabular*}

\bigskip

\begin{data}
\leftpart
blah blah blah blah blah blah blah blah blah

blah blah blah blah blah blah blah blah blah blah blah blah

\rightpart

blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah      
blah blah blah
\end{data} 

\end{document}

The showframe option is of course just for this example. Never use the obsolete a4wide package.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .