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 use tabular in header with package fancyhdr. I added settototalheight to calculate the header height. Following is a small example. The question is that header doesn't align with the decorative line at the right end. But it does at the left end. What is the problem?

\documentclass[titlepage,a4paper]{article}

\usepackage{fancyhdr}
\usepackage{calc}

\usepackage[english]{babel}
\usepackage{datetime}   
\renewcommand{\dateseparator}{-}
\newcommand{\headertoday}{\the\year \dateseparator \twodigit\month \dateseparator \twodigit\day}

\usepackage[lmargin=1.800000cm,rmargin=1.000000cm,tmargin=2.500000cm,bmargin=1.000000cm]{geometry}

%### define an environment to have a local `\arraystretch'
\newenvironment{TabLocalVerticalSpacing}[1]
  {\def\arraystretch{#1}\tabular}
  {\endtabular}
%#####################################

\pagestyle{fancy}
\fancyhf{}
\newcommand\leftheadercalc[1]{%
\begin{TabLocalVerticalSpacing}{#1}[b]{@{}ll}\footnotesize{Static Calculation Foundation Loads and concrete columns basic parameter}&\footnotesize{}\\\footnotesize{Project: xxxxxx}&\footnotesize{}\end{TabLocalVerticalSpacing}
}
\newcommand\rightheadercalc[1]{%
\begin{TabLocalVerticalSpacing}{#1}[b]{rr@{}}\footnotesize{Date:}&\footnotesize{\headertoday}\\\footnotesize{Page:}&\footnotesize{\thepage}\end{TabLocalVerticalSpacing}
}
\newcommand\midheadercalc[1]{%
\begin{TabLocalVerticalSpacing}{#1}[b]{cc}\footnotesize{}&\footnotesize{}\\\footnotesize{}&\footnotesize{}\end{TabLocalVerticalSpacing}
}
\settototalheight\headheight{\maxof{\leftheadercalc{0.600000}}{\rightheadercalc{0.600000}}{\midheadercalc{0.600000}}}
\lhead{\leftheadercalc{0.600000}}
\rhead{\rightheadercalc{0.600000}}
\chead{\midheadercalc{0.600000}}

%########## header decorative lines
\makeatletter
\def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi%
\hrule\@height 0.500000pt \@width\headwidth\vskip1.000000pt
\hrule\@height 0.500000pt\@width\headwidth}}    
\makeatother


%########## footer decorative lines
\makeatletter   
\def\footrule{{\if@fancyplain\let\footrulewidth\plainfootrulewidth\fi%
\hrule\@height 0.500000pt \@width\headwidth\vskip1.000000pt 
\hrule\@height 0.500000pt\@width\headwidth}}    
\makeatother

\newcommand\leftfootercalc[1]{%
\footnotesize{xxx GmbH}
}
\newcommand\rightfootercalc[1]{%
\footnotesize{Document: g-zzz}
}
\newcommand\midfootercalc[1]{%
\footnotesize{Principal: civil eng. yyy}
}
\settototalheight\footskip{\maxof{\leftfootercalc{0.600000}}{\rightfootercalc{0.600000}}{\midfootercalc{0.600000}}}
\lfoot{\leftfootercalc{0.600000}}
\rfoot{\rightfootercalc{0.600000}}
\cfoot{\midfootercalc{0.600000}}

\begin{document}
balala
\end{document}
share|improve this question
add comment

1 Answer

You need to look for where a space is introduced; an easy way to do that is to enclose sections of the code with LaTeX3 \ExplSyntaxOn and \ExplSyntaxOff tags (just include the expl3 package).

\ExplSyntaxOn
\newcommand\rightheadercalc[1]{%
\begin{TabLocalVerticalSpacing}{#1}[b]{rr@{}}\footnotesize{Date:}&\footnotesize{\headertoday}\\\footnotesize{Page:}&\footnotesize{\thepage}\end{TabLocalVerticalSpacing}
}
\ExplSyntaxOff

This corrected the problem on the top right, which by inspection should have had a % at the end.

\end{TabLocalVerticalSpacing}%

enter image description here

Same for the bottom footer!

share|improve this answer
    
@Yiannis: due to leave, i can't test your method. from your answer, i found two interesting things. first, use \ExplSyntaxOn and \ExplSyntaxOff. it looks like syntax check. but it can cancel out redundant space. i will refer to expl3's manual to see what it means. second, add % at the end of sentence. what i only know is that % just means a comment. but here it means something else more. i will try your answer as soon as i come back. thanks a lot. –  warem Mar 11 '11 at 0:35
    
@warem: The % is really just a comment, but the line end is taken as a space(!) which is commented out by %. Spaces after macros are ignored, but not after { or }. –  Martin Scharrer Mar 11 '11 at 9:16
    
@Yiannis: i am using Miktex 2.4. adding \usepackage{expl3} said that file expl3.sty not found. –  warem Mar 14 '11 at 10:50
    
@Yiannis: if i installed latest expl3 manually then compiled, i got this error: Package l3names Error: Required primitive not found: \pdfstrcmp. after type H for immediately help, i got LaTeX3 requires the e-TeX primitives and \pdfstrcmp. this is available in pdftex 1.3 or later. for miktex 2.4, the pdftex version is 3.141592-1.21a. so what's the matter? –  warem Mar 14 '11 at 13:05
    
@warem you need to update the MikTeX distribution as you are one version behind on pdftex. If you do not want to, just adding the missing "%" would do the trick. –  Yiannis Lazarides Mar 14 '11 at 17:24
show 4 more comments

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.