# Page Content Misalignment

I've started using LyX to write technical specification documents. As a result of numerous hasty Google searches (many ending at this site) I have cobbled together a LyX file that mostly delivers what I'm after.

However, I've found that when I render it to PDF using xetex my first page after the title (a Part) seems to always be vertically misaligned relative to the other pages.

Question: what have I overlooked / mangled ?

Note that I've got some stuff in my preamble to make Parts look like Chapters (can't remember why anymore).

My MWE is below, if you process it to PDF using XeTeX you'll find that the heading for "Document Control" is vertically misaligned relative to "Background Information". All my other Parts (not in the MWE) align with the "Background Information" part. My tests indicate that it doesn't matter which is the first Part - it will always misalign (viewed in OSX Preview.app with 2-page view):

The mis-alignment extends as far as the footer. So it's like the entire page body has been vertically bumped up a number of pixels

I've found that changing the size of the header image (logo.png) causes the scale of the mis-alignment to change.

Being a total newbie to TeX I am at a loss to explain it.

# MWE

logo.png is 464px x 60px

The documentclass is report

#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\textclass report
\begin_preamble
\usepackage[a4paper]{geometry}
\usepackage[table]{xcolor}
\usepackage{background}

\usepackage{lastpage}
\usetikzlibrary{calc,shapes,arrows}

%tables
\arrayrulecolor[RGB]{127,127,127}
\setlength{\arrayrulewidth}{0.25mm}

\usepackage[explicit]{titlesec}

% make part like a chapter
\titleclass{\part}{top}
\titleformat{\part}
[display]
{\normalfont\Huge\bfseries}
{\titlerule[5pt]\vspace{3pt}\titlerule[2pt]\vspace{3pt}\MakeUppercase{\partname} \thepart}
{0pt}
{\titlerule[2pt]\vspace{1pc}\huge\MakeUppercase{#1}}
\titlespacing*{\part}{0pt}{0pt}{20pt}

% make chapter like a section (no newpage)
\titleclass{\chapter}{straight}
\titleformat{\chapter}
[display]
{\centering\normalfont\Huge\bfseries}
{\titlerule[5pt]\vspace{3pt}\titlerule[2pt]\vspace{3pt}\MakeUppercase{\chaptertitlename} \thechapter}
{0pt}
{\titlerule[2pt]\vspace{6pt}\huge\MakeUppercase}
\titlespacing*{\chapter}{0pt}{0pt}{40pt}

% make section have a background
\titleformat{\section}
[display]
{\normalfont\Large\bfseries}
{\thesection}
{0pt}
{\colorbox{blue!20}{\parbox{\dimexpr\textwidth-2\fboxsep}{#1}}}
%

% make subsubsection italicised
\titleformat{\subsubsection}
[display]
{\normalfont\bfseries}
{\thesubsubsection}
{0pt}
{\textit{#1}}
%

%Document variables
\newcommand*{\customer}{Foo}
\newcommand*{\customerlong}{Bar}
\newcommand*{\docversion}{Draft Version 0.0.1}

%Page footer - horiz line
\def\footrule{{
\vskip-\footruleskip\vskip-\footrulewidth
\color{\footrulecolor}
\footrulewidth\vskip\footruleskip
}}

%page borders
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\footrulewidth}{1pt}
\newcommand{\footrulecolor}{blue}

%page candy
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
%\fancyfoot[C]{\bfseries \thepage} % except the center
\fancyfoot[L]{\textbf{\textcolor{orange}{\scriptsize Confidential}}}
\fancyfoot[C]{\textbf{\textcolor{blue}{\Large website.com}} }
\fancyfoot[R]{\textbf{\textcolor{orange}{\scriptsize Page \thepage\ of \pageref{LastPage} }} }
\renewcommand{\footrulewidth}{1pt}
\renewcommand{\footrulecolor}{blue}
}
\end_preamble
\options demo
\use_default_options true
\begin_modules
theorems-ams
eqs-within-sections
figs-within-sections
\end_modules
\maintain_unincluded_children false
\begin_local_layout

\end_local_layout
\language british
\language_package default
\inputencoding auto
\fontencoding global
\font_roman lmodern
\font_sans lmss
\font_typewriter lmtt
\font_default_family sfdefault
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100

\graphics xetex
\default_output_format pdf4
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize 12
\spacing single
\use_hyperref false
\papersize a4paper
\use_geometry true
\use_amsmath 1
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 2cm
\topmargin 2cm
\rightmargin 2cm
\bottommargin 4.75cm
\footskip 2.5cm
\secnumdepth -1
\tocdepth 0
\paragraph_separation skip
\defskip 16pt
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle fancy
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false

\begin_body

\begin_inset Graphics
filename logo.png

\end_inset

\end_layout

\begin_layout Center Footer
\begin_inset ERT
status open

\begin_layout Plain Layout

\backslash
textbf{
\backslash
textcolor{blue}{
\backslash
Large website.com}}
\end_layout

\end_inset

\end_layout

\begin_layout Left Footer
\begin_inset ERT
status open

\begin_layout Plain Layout

\backslash
textbf{
\backslash
textcolor{orange}{
\backslash
scriptsize Confidential}}
\end_layout

\end_inset

\end_layout

\begin_layout Right Footer
\begin_inset ERT
status open

\begin_layout Plain Layout

\backslash
textbf{
\backslash
textcolor{orange}{
\backslash
scriptsize Page
\backslash
thepage
\backslash
of
\backslash
pageref{LastPage} }}
\end_layout

\end_inset

\end_layout

\begin_layout Title
\begin_inset Graphics
filename logo.png

\end_inset

\begin_inset Newline newline
\end_inset

Specification
\begin_inset Newline newline
\end_inset

\begin_inset ERT
status open

\begin_layout Plain Layout

\backslash
docversion
\end_layout

\end_inset

\begin_inset Newline newline
\end_inset

\begin_inset ERT
status open

\begin_layout Plain Layout

\backslash

\end_layout

\end_inset

\begin_inset Newline newline
\end_inset

\begin_inset ERT
status open

\begin_layout Plain Layout

\backslash
customerlong
\end_layout

\end_inset

\begin_inset Newline newline
\end_inset

A Title
\end_layout

\begin_layout Part*

\lang english
Document Control
\end_layout

\begin_layout Section*

\lang english
\end_layout

\begin_layout Standard

\lang english
Generic blurb
\end_layout

\begin_layout Section*

\lang english
Document Version History
\end_layout

\begin_layout Standard
a table
\end_layout

\begin_layout Part*
Background Information
\end_layout

\begin_layout Section*
Project Taxonomy
\end_layout

\begin_layout Standard
a table
\end_layout

\begin_layout Section*
Stakeholders
\end_layout

\begin_layout Itemize
List of direct project stakeholders
\end_layout

\begin_layout Section*
Other Parties
\end_layout

\begin_layout Itemize
List of ancialliary parties
\end_layout

\begin_layout Section*
Exclusions
\end_layout

\begin_layout Standard
Generic stuff
\end_layout

\begin_layout Section*
\end_layout

\begin_layout Standard
Some useful information
\end_layout

\begin_layout Section*
\end_layout

\begin_layout Standard
Some useful information
\end_layout

\begin_layout Section*
\end_layout

\begin_layout Standard
Some useful information
\end_layout

\end_body
\end_document


# Update

Further testing has indicated that simply having some plain text after the title will produce the same offset effect - so it's not the Part definitions that are having the problem.

• From your 'MWE' is it not clear which \documentclass is used. The lyx output is not really helpful, in my point of view. – user31729 May 13 '14 at 8:02
• @ChristianHupfer, doc class is "Report". I've updated my question accordingly. What output would make the MWE better ? – LRE May 13 '14 at 8:12
• I would delete the lines until \begin_preamble and insert \documentclass{report} – user31729 May 13 '14 at 8:14
• @ChristianHupfer Come on, that was a perfectly valid LyX file, just copy it, save as as something.lyx and open it in LyX. Now it's not valid anything! One can export LaTeX source code from LyX, request that instead. – Torbjørn T. May 14 '14 at 5:32
• @TorbjørnT - you beat me to restoring the MWE. Thanks – LRE May 14 '14 at 21:41

After compiling the document, open the log (Document --> LaTeX log), and step through the warnings. Likely you'll find a warning like

Package Fancyhdr Warning: \headheight is too small (12.0pt):
Make it at least 68.36833pt.
We now make it that large for the rest of the document.
This may cause the page layout to be inconsistent, however.


This explains what the problem is, what you should do to fix it, and why the problem only occurs once, for the first \part.

The \headheight is the height of the header, which you in your preamble have set to 12pt (\setlength\headheight{12pt}). This is not large enough to contain the image in the header, so for the page with the first \part the header will just overflow the allotted space. As the warning states, after this page, the \headheight is modified by LaTeX, so for the next pages the problem does not occur.

To fix it, change the \headheight in your preamble to be (at least) the value reported in the log. The exact value reported will depend on how large the content of the header is, so check your own log -- I inserted a different image for my test.

• @Torbojorn-t, thank you so very very very much - you've made my day – LRE May 14 '14 at 21:39
• inerestingly my log said 33.xxx points - but still it did the trick – LRE May 14 '14 at 21:40
• @LRE I used a different image, that was probably higher than yours, so it's not so strange that you got a different value. – Torbjørn T. May 15 '14 at 5:29