3

I'm really stuck and I would appreciate any advice. I need to design a header for a technical report that looks like this:

header

The first column is 2.5 cm in width, the second column has 11cm, the third 1cm and the fourth 1cm. The height of the first row is 1.3 cm and the second row has 1 cm. I need the header to have this measures as we have some people using open office and some people using LaTex.

My MWE so far, looks like this:

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{array}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage[hmargin=2cm,top=4cm,headheight=6cm,footskip=65pt]{geometry}
\usepackage[version=4]{mhchem} % loads some package that allows to use "\arrayrulewidth"
\usepackage{lipsum}
    
% new columns definition
\newcolumntype{M}[1]{@{}>{\centering\arraybackslash}m{#1}@{}}
\newcolumntype{N}{@{}m{0pt}@{}}
                
\pagestyle{fancy}
\renewcommand\headrulewidth{0pt} % no line between document and header
\fancyhf{} % clear header and footer
\fancyhead[C]{%
    \begin{tabular}{|M{2.5cm-1.25\arrayrulewidth}|M{11cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|N}
        \hline
        \multirow{2}{*}{\includegraphics[height=2.2cm,width=2.2cm]{example-image}} & \makecell{Report \\ \footnotesize{from a research center}} & \multicolumn{2}{M{2cm-1.5\arrayrulewidth}|}{\makecell{Deliverable\\ 2.0}} & \rule{0pt}{1.3cm}\\
        \cline{2-4} 
        & \multicolumn{2}{M{12cm-1.5\arrayrulewidth}|}{\makecell{Report title \\ and number}}     & \makecell{Page \\ \thepage} & \rule{0pt}{1cm}\\
        \hline
    \end{tabular}
}

\begin{document}

\section{Section title}
%% add this if you want the fancy style also on the first page of a chapter:
\thispagestyle{fancy}
\subsection{Subsection title}
\lipsum[1-10]

\end{document}

enter image description here

The problem is that the image in the left cell is squared and I don't know how to place it in the middle (vertical alignment). I would appreciate any input that you can provide.

There are vertical alignment issues in the other cells, as they appear to be below the center of the cell. But it is not as troublesome as the image in the left cell.

2
  • Do you have to specify the image height?
    – hesham
    Jul 28, 2020 at 2:58
  • @hesham, not necesarily. I specified the height to force the image to be squared (like the logo of the research center) since the "example-image" aspect ratio is not 1:1.
    – P.M.
    Jul 28, 2020 at 15:05

3 Answers 3

5

One workaround for your main issue is using minipage for placing the image inside the table cell with centering and the full width of the cell. You can then use \vspace to adjust its vertical alignment. You can change the number of -0.8 at \vspace{-0.8\baselineskip} for shifting the image up or down in the cell.

You then obtain something like this:

enter image description here

Full code

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{array}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage[hmargin=2cm,top=4cm,headheight=6cm,footskip=65pt]{geometry}
\usepackage[version=4]{mhchem} % loads some package that allows to use "\arrayrulewidth"
\usepackage{lipsum}

% new columns definition
\newcolumntype{M}[1]{@{}>{\centering\arraybackslash}m{#1}@{}}
\newcolumntype{N}{@{}m{0pt}@{}}

\pagestyle{fancy}
\renewcommand\headrulewidth{0pt} % no line between document and header
\fancyhf{} % clear header and footer
\fancyhead[C]{%
    \begin{tabular}{|M{2.5cm-1.25\arrayrulewidth}|M{11cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|N}
        \hline
        \multirow{2}{*}{\begin{minipage}{1\linewidth}
                \centering
                \vspace{-0.8\baselineskip}
                \includegraphics[height=2.2cm,width=2.2cm]{example-image}
                \end{minipage}}
                & \makecell{Report \\ \footnotesize{from a research center}} & \multicolumn{2}{M{2cm-1.5\arrayrulewidth}|}{\makecell{Deliverable\\ 2.0}} & \rule{0pt}{1.3cm}\\
        \cline{2-4} 
        & \multicolumn{2}{M{12cm-1.5\arrayrulewidth}|}{\makecell{Report title \\ and number}}     & \makecell{Page \\ \thepage} & \rule{0pt}{1cm}\\
        \hline
    \end{tabular}
}

\begin{document}
    
    \section{Section title}
    %% add this if you want the fancy style also on the first page of a chapter:
    \thispagestyle{fancy}
    \subsection{Subsection title}
    \lipsum[1-10]
    
\end{document}
4

Like this?

enter image description here

\documentclass[a4paper,10pt]{article}
\usepackage[hmargin=2cm,top=4cm,headheight=6cm,footskip=65pt]{geometry}
\usepackage{graphicx}
\usepackage{array, makecell, multirow}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear header and footer
\renewcommand\headrulewidth{0pt} % no line between document and header
\fancyhead[C]{\centering%
    \begin{tabular}{|P{25mm}|c |P{1cm}|P{1cm}|@{}c@{}}
        \hline
\multirow{5}{=}[4.4mm]{\centering\includegraphics[height=22mm, width=22mm]{example-image}}
    &   \multicolumn{1}{P{110mm}|}{\makecell{\fontsize{18pt}{20pt}\selectfont\textbf{Report}\\
                                           \large  from a research center}}
            & \multicolumn{2}{P{20mm}|}%
                          {\makecell{Deliverable\\   2.0}}
                            & \rule[-5mm]{0pt}{13mm}\\
    \cline{2-5}
    &   \multicolumn{2}{P{120mm}|}%
                    {\makecell{Report title\\    and number}}
            &   Page\newline
                \thepage    & \rule[-5mm]{0pt}{10mm}\\
    \hline
    \end{tabular}
}

\usepackage{lipsum}
\usepackage{hyperref} % had to be last in preamble

\begin{document}

\section{Section title}
\thispagestyle{fancy}
\subsection{Subsection title}
\lipsum\lipsum

\end{document}
2

Another variant, using \multirowcell and taking into account that the number argument of multirow is not the number of rows, but the number of lines, which is not necessarily the same. In addition, your cells are unusual, since they include invisible rules to ensure a fixed height. So I put the multirow in the second row, with a negative, decimal number argument.

Unrelated: hyperref should be loaded as the last package, with very few exceptions.

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{array}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage[hmargin=2cm,top=4cm,headheight=6cm,footskip=65pt]{geometry}
\usepackage[version=4]{mhchem} % loads some package that allows to use "\arrayrulewidth"
\usepackage{lipsum}

% new columns definition
\newcolumntype{M}[1]{@{}>{\centering\arraybackslash}m{#1}@{}}
\newcolumntype{N}{@{}m{0pt}@{}}

\pagestyle{fancy}
\renewcommand\headrulewidth{0pt} % no line between document and header
\fancyhf{} % clear header and footer
\fancyhead[C]{%
    \begin{tabular}{|M{2.5cm-1.25\arrayrulewidth}|M{11cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|M{1cm-1.25\arrayrulewidth}|N}
        \hline& \makecell{Report \\ \footnotesize{from a research center}} & \multicolumn{2}{M{2cm-1.5\arrayrulewidth}|}{\makecell{Deliverable\\ 2.0}} & \rule{0pt}{1.3cm}\\
        \cline{2-4}
        \multirowcell{-4.8}{\includegraphics[height=2.2cm,width=2.2cm]{example-image}}
        & \multicolumn{2}{M{12cm-1.5\arrayrulewidth}|}{\makecell{Report title \\ and number}} & \makecell{Page \\ \thepage} & \rule{0pt}{1cm}\\
        \hline
    \end{tabular}
}

\begin{document}

\section{Section title}
%% add this if you want the fancy style also on the first page of a chapter:
\thispagestyle{fancy}
\subsection{Subsection title}
\lipsum[1-10]

\end{document} 

enter image description here

You must log in to answer this question.

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