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'm trying to create question paper using Latex. Sample copy of expected header for first page is mentioned below. Note: Image above "First Page Header". Can you please suggest, how can I add table in header with Image on left hand-side as mentioned below. Is there any recommended package? enter image description here

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

Save the table in a box and call it with \usebox in the header.

In this example, I use the tabularx package because you can then force the table to fit the width of the page. I also used the multirow package to allow the image to span multiple rows of the table. Forcing height is a bit more difficult. So, I just tried a couple of values for resetting \arraystretch and the height of the included image to get the appearance to look like a good fit.

Also, I'm not sure how you want the header placed. I passed the key includehead to the geometry package to embed the header in the textbody. It doesn't have to be done this way, but otherwise you'll have to play with the placement. Or you can make the top=0.5in or something like that to get a better appearance for the header and margins.

\documentclass{article}
\usepackage[margin=1in,headheight=5\baselineskip,headsep=1\baselineskip,includehead]{geometry}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{multirow}
%% set up and width for the tabularx environment to expand and fit to.
\newlength{\headerwidth}
\setlength{\headerwidth}{\textwidth}
\newsavebox{\myheader}
\begin{lrbox}{\myheader}%
    \begin{minipage}[b]{\headerwidth}
    \renewcommand{\arraystretch}{1.29}%
    \begin{tabularx}{\headerwidth}{|@{}c@{}|c|X|c|}\hline
    \multirow{3}{*}{\includegraphics[height=0.65in]{example-image-a}}
                                                & \multicolumn{2}{c|}{ TEXT ONE VALUE }                 & Text Four \\\cline{2-3}
                                                & \multirow{2}{*}{1234} & \centering\textbf{Text two}   &           \\\cline{3-3}
                                                &                       & \centering\textbf{Text Three} &           \\\hline
    \end{tabularx}
    \par
    \bfseries
    Time: 45 Min \hspace*{\fill} 
    Date:        \hspace*{\fill}
    Marks:45
    \end{minipage}
\end{lrbox}
%% Setting up the header
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\lhead{}
\chead{\usebox{\myheader}}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{}

\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\end{document}

enter image description here

Addendum

I got a bit frustrated with the multirow package not really lining things up the way I would like them to. So here's an example that avoids using the multirow package. Instead, I use \raisebox to adjust the placement of the image and the number 1234.

I wanted to center the image. Since the baseline of the image in the bottom of the graphic, I used \raisebox to raise the image by half its height. To keep this from affecting the height of the current row, I used the optional arguments to \raisebox to ensure that it had no height or depth.

Also, to help preserve a uniformity in the appearance of the rows, I created some struts. For lack of a better name, the one I'm calling a horizontal "strut" (someone please tell the correct terminology for this use of an invisible box which takes up horizontal space).

\documentclass{article}
\usepackage[margin=1in,top=0.5in,headheight=5\baselineskip,headsep=1\baselineskip,includehead]{geometry}
\usepackage{tabularx}
\usepackage{graphicx}
%% some invisible "struts" to help define the structures and row heights.
\newcommand{\aevstrut}{\rule{0pt}{2.9ex}}
\newcommand{\aehstrut}{\rule{0.45em}{0pt}}
\newcommand{\textfour}{%
    \begin{tabular}{|c|c|c|c|}
        \aevstrut\aehstrut &
        \aehstrut &
        \aehstrut &
        \aehstrut \\\hline
    \end{tabular}}
%% set up and width for the tabularx environment to expand and fit to.
\newlength{\headerwidth}
\setlength{\headerwidth}{\textwidth}
\newsavebox{\myheader}
\begin{lrbox}{\myheader}%
    \begin{minipage}[b]{\headerwidth}
    \renewcommand{\arraystretch}{1.29}%
    \begin{tabularx}{\headerwidth}{|@{}c@{}|c|X|c|}\hline
                                                & \multicolumn{2}{c|}{ TEXT ONE VALUE }                             & {\aevstrut}Text Four \\\cline{2-3}
        \raisebox{\dimexpr0.73ex-0.5\totalheight\relax}[0pt][0pt]
                 {\includegraphics[height=\dimexpr0.65in+1.5ex\relax]{example-image-a}}%
                                                &                                   & \centering\textbf{TEXT TWO}   & {\aevstrut}\textfour \\\cline{3-3}
                                                & \raisebox{2.5ex}[0pt][0pt]{1234}  & \centering\textbf{TEXT THREE} & {\aevstrut}          \\\hline
    \end{tabularx}
    \vspace{-0.5ex}\par
    \bfseries
    Time: 45 Min \hspace*{\fill} 
    Date:        \hspace*{\fill}
    Marks:45
    \end{minipage}
\end{lrbox}
%% Setting up the header
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\lhead{}
\chead{\usebox{\myheader}}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{}

\usepackage{lipsum}
\begin{document}

\lipsum[1]

\end{document}

enter image description here

share|improve this answer
    
Thanks a lot, you are genius ; This works perfectly. –  Pawan Mude Jun 18 '13 at 4:57
    
Is there a way to restrict chead only on the first page? Currently it's appearing on all pages. –  Pawan Mude Jun 18 '13 at 9:08
    
As a workaround , i added it in \fbox{\usebox{\myheader}} FYI: I'm using documentclass{exam} –  Pawan Mude Jun 18 '13 at 11:19
1  
Just place \chead{<new content>} with text that will definitely appear starting on the second page. <new content> can be anything including an empty string. –  A.Ellett Jun 18 '13 at 13:32
1  
Alternatively, you could also do something like \chead{\ifnum\thepage=1\usebox{\myheader}\else$<$other content$>$\fi} in the preamble. –  A.Ellett Jun 18 '13 at 13:34
show 1 more 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.