2

I'm not completely sure if this topci is repeated, but anyway... I'm writing some company reports that have a special header and footer layout containing tables. I have been able to configure the layout using fancyhdr, but the tables go out of the page. Below I provide images of the desired layout and the obtained, and also the code I'm using.

Desired layout - Header Desired layout - Header

Desired layout - Footer Desired layout - Footer

Result - Header Result - Header

Result - Footer Result - Footer

As you can see, the text above the footer overlaps with the line of the table.

Finally, the code:

\documentclass[letterpaper,10pt,openany]{report}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
 \usepackage{array}
 \usepackage[spanish]{babel}
 \usepackage{graphicx}
 \usepackage{float}
 \usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[paperwidth=21cm, paperheight=28.8cm, top=3.55cm, left=2.03cm, bottom=7.28cm, right=1.27cm]{geometry}
% Title Page
\title{}
\author{}
  \setlength{\headheight}{127.69005pt}
  \setlength{\parindent}{0pt}
  \setlength{\parskip}{\baselineskip}

\setlength{\footskip}{0pt}
\pagestyle{fancy}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[CE,CO,LE,LO,RE,RO]{} %% clear out all headers
\fancyhead[C]{%
          \begin{tabular}{|m{3.6375cm}|m{5.3475cm}|m{7.0275cm}|m{1.6875cm}|}
          \hline
           \multicolumn{4}{|m{17.66cm}|}{\centering \vspace{1.5\baselineskip}\includegraphics[width=3cm]{LOGO.png}} \\[1.23cm] \hline
          Cliente:  & REF.  & \centering Lugar: Por definir & Hoja: \\[0.77cm] \hline
           \multicolumn{3}{|m{16.10cm}|}{\centering \vspace{1.5\baselineskip} Titulo} & \multicolumn{1}{m{1.6cm}|}{Total:} \\[0.82cm] \hline
          \end{tabular}%
}
\fancyfoot[CE,CO,LE,LO,RE,RO]{} %% clear out all footers
\fancyfoot[C]{%
          \begin{tabular}{|m{5.67cm}|m{5.75cm}|m{5.1cm}|m{1.52cm}|}
          \hline
      & Preparado por: & Fecha:  & Ver. \\[0.96cm] \hline 
          \end{tabular}%
}

\begin{document}

What am I exactly doing wrong? Thanks in advance!

Charlie

3
  • Simply resize the width of your columns. Feb 14, 2014 at 16:31
  • Either you need bigger paper or smaller headers and footers. An easy fix would be to use \resizebox. Feb 14, 2014 at 19:16
  • Aha! The widths specified for tabular are for the text itself and does not include the spacing between columns. Feb 14, 2014 at 19:34

1 Answer 1

2

Please take a look (explanations are below):

\documentclass[letterpaper,10pt,openany]{report}
\usepackage[paperwidth=21cm, paperheight=28.8cm, top=3.55cm, left=2.03cm, bottom=7.28cm, right=1.27cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage[spanish]{babel}
\usepackage[demo]{graphicx}
\usepackage{float}
\usepackage{helvet}

\renewcommand{\familydefault}{\sfdefault}


\setlength{\headheight}{141pt}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}

\setlength{\footskip}{22.58pt}
\pagestyle{fancy}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{} %% clear out all headers and footers
\fancyhead[C]{%
\begin{tabular}{
  |m{\dimexpr.22\textwidth-2\tabcolsep-1.25\fboxrule\relax}
  |m{\dimexpr.28\textwidth-2\tabcolsep-1.25\fboxrule\relax}
  |m{\dimexpr.3\textwidth-2\tabcolsep-1.25\fboxrule\relax}
  |m{\dimexpr.2\textwidth-2\tabcolsep-1.25\fboxrule\relax}|
}
\hline
\multicolumn{4}{|m{\dimexpr\textwidth-2\tabcolsep-2\fboxrule\relax}|}{%
  \centering\rule[-0.3cm]{0pt}{1cm}\raisebox{-\height}{%
    \includegraphics[width=3cm,height=0.7cm]{LOGO.png}}} 
\\[1.23cm] 
\hline
Cliente:  & REF.  & \centering Lugar: Por definir & Hoja: 
\\[0.77cm] 
\hline
\multicolumn{3}{
  |m{\dimexpr.3\textwidth-2\tabcolsep-1.5\fboxrule\relax}|}{\centering \vspace{1.5\baselineskip} Titulo} 
  & \multicolumn{1}{m{\dimexpr.2\textwidth-2\tabcolsep-1.5\fboxrule\relax}|}{Total:} 
\\[0.82cm] \hline
\end{tabular}%
}
\fancyfoot[C]{%
  \begin{tabular}{
    |m{\dimexpr.3\textwidth-2\tabcolsep-1.25\fboxrule\relax}
    |m{\dimexpr.3\textwidth-2\tabcolsep-1.25\fboxrule\relax}
    |m{\dimexpr.3\textwidth-2\tabcolsep-1.25\fboxrule\relax}
    |m{\dimexpr.1\textwidth-2\tabcolsep-1.25\fboxrule\relax}|
  }
  \hline
  & Preparado por: & Fecha:  & Ver. \\[0.96cm] \hline 
  \end{tabular}%
}

\begin{document}

text

\end{document}

enter image description here

Your columns width specifications had two problems:

  1. You were not taking into account \tabcolsep (the horizontal length separating the content from the column "border") and \fboxrule (the thickness of the rules).

  2. You were using absolute lengths, so a lot of trial-error were required and a simple change in the page layout will make you start from the beginning the calculations. Instead of this, I used fractions of \textwidth to calculate the widths; in this way, no matter if you change the width of the text area, the columns width will automatically accommodate to span the full text width.

I had to change the values for \headheight and \footskip; perhaps you will need to adjust thos velues depending on the actual height of the image.

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

You must log in to answer this question.

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