I auto generate a postscript (landscape) calendar each month using the wonderful remind program, after which I run the ps file through ps2pdf to produce a pdf file. I need to automate inclusion of some additional information in the heading of the calendar page. I was unable to find a way to do that using remind but I did discover a solution for adding the enhanced header by using pdftk: I created a pdf file with just the header as content, then overlayed the calendar onto it using pdftk. But now, owing to slow development of pdftk, I've had to remove it from my system, since its presence was blocking important updates. So I'm looking for an alternate means of overlaying the header text onto the calendar.

In my search for alternatives, I ran across https://askubuntu.com/questions/712691/batch-add-header-footer-to-pdf-filesm which offered a decent basis on which a beginner like me could experiment with using LaTeX (pdflatex) to accomplish my task. Here is the MWE, based on that post, I've come up with so far and that gives passable results:



\fancyfoot[CO]{***For emergencies don't call us, we'll call you!***}

\fancyhead[L]{\small After hours contacts: \\ Carrier 1: 111-2222 \\ Carrier 2 111-3333 \\ Carrier 3 111-4444 \\}
\fancyhead[C]{\LARGE My Fancy Calendar Header for \\}
\fancyhead[R]{\small Text here \\ More text here \\ Yet more text here \\ And so forth \\ Final line added to fix misalignment issue}

\includepdf[pagecommand={\thispagestyle{fancy}},pages=1 ]{Feb-2018.pdf}


I run pdflatex on the .tex file containing that content and get an overlain calendar pdf.

As will be evident I'm trying to suppress page numbering and the horizontal rule. The results I get using this do overlay the pdf calendar properly and look ok, although the text on the right side of the header looks to start one line lower than the text on the left for some reason. So, although it gives passable results, cosmetically it does have some shortcomings.

I just wanted to ask whether it seems to the LaTeX cognoscenti here that I am going about accomplishing my task in a sensible way? I understand there may be other ways of accomplishing the aim using LaTeX: for example, I ran across indications that superimposing an image file as the header may work, too. I should mention that the calendar I produce already has a centered heading that includes the name of the month and the year, so my enhanced heading has to sort of fit around it (above, to the left, and to the right). Further pointers, tips, and/or improvements will be appreciated.

LATER EDIT: I think a squat table (about .75 inch tall) of one row and three columns, without borders, either incorporated into the header or just positioned at the very top of the page, might give the best and most predictable results. The middle column would need to be significantly wider than the outside two. Using the standard header and trying to fit multiple lines as I'm doing results in the various lines pushing each other down the page a bit. With the header elements confined to table columns, the content should be more controllable.

YET LATER EDIT: I've decided to stick with the MWE I've given above as the solution to my issue. cfr's explanation about baselines helped me sort the slight misalignment I'd been seeing and, with the same number of items in left and right sides of the heading, the final output is quite acceptable.

  • pdftk is dead i.e. development is not slow, but no more. Very unfortunate: there is no satisfactory replacement. Fortunately, I can keep pdftk on Arch, but Fedora is more problematic. – cfr Dec 27 '17 at 1:52
  • The referenced system runs Void. The presence of gcc-7, gotten with a recent system update, is incompatible with libgjc, a library file apparently essential to pdftk. Wasn't sure whether pdftk is moribund or dead & didn't want to overstate the case. – MJiller Dec 27 '17 at 2:40
  • Yes, it is a pain if you want to keep using it on a current system. Has been for a bit on Arch, which is pretty much always on the latest everything. Though the binary package I'm using now is nowhere near as painful as the previous one. (All of this is AUR, of course.) – cfr Dec 27 '17 at 4:09
  • (Of course, it is compiling the compiler which is the painful bit - compiling pdftk itself is fine.) – cfr Dec 27 '17 at 4:11

TeX aligns to the baseline. The left header contains an additional empty line. Hence, it is one line less tall than the content of the right header. To see this, try adding xxx at the end of each header spec.

\fancyhead[L]{\small After hours contacts: \\ Carrier 1: 111-2222 \\ Carrier 2 111-3333 \\ Carrier 3 111-4444\\ xxx}


\fancyhead[R]{\small Text here \\ More text here \\ Yet more text here \\ And so forth xxx}

aligned headers

Note the alignment to the baseline. The point here is that TeX is always starting on the baseline. So it doesn't start at the top of the box of header content. It takes the header content as a box and puts it on the current baseline. This point is at the baseline of the header, which is placed according to the values geometry calculates from the headheight, paperheight, top margin, headsep, etc.

When typesetting the content of the boxed stuff for each header part, however, TeX starts at the baseline of the first line of content. So this is the baseline on which you set After hours contacts and Text here. It keeps going until the end. The height of the box thus depends on the number of lines and the height of each line. The two boxes are then aligned at their baselines i.e. at the bottom. So, the shorter one has more space above it than the taller one, as is the case with trees, tower blocks and omnivores: shorter ones have more space above their tops, if the ceiling, sky or roof is at the same distance from the ground.

So, you can align them by making the content always take the same vertical space. However, this is error prone. If you want them aligned at the top, as you seem to, it is better to force that explicitly. Also, don't leave spaces at the beginning of lines or things may or may not end up raggedy. If you are trying to use spaces in the source for alignment: don't. It won't work. Spaces are gluey. They shrink and stretch. Hence, the space between words varies, even when the font is constant. Moreover, they are regularly eaten by various things.

Don't gobble page numbering. That can cause problems. Just don't typeset the page numbers.

For example,



      After hours contacts:\\Carrier 1: 111-2222\\Carrier 2 111-3333\\Carrier 3 111-4444\\Aardvarks 'R Ace
      \LARGE My Fancy Calendar Header for 
      Text here\\More text here\\Yet more text here\\And so forth
\fancyfoot[CO]{***For emergencies don't call us, we'll call you!***}%

\includepdf[pagecommand={\thispagestyle{fancy}},pages=1 ]{enfys}


produces the following (showframe shows the text area and margins laid out by geometry - obviously remove this option in your real document):

aligned headers at top

Note that the left header contains more lines of content than the right, but they are aligned at the top, so 'start' at the same vertical point beneath the top of the paper.

  • Personally, I'd do this with coffins rather than minipages, but the former are not to everyone's taste. – cfr Dec 27 '17 at 4:49
  • Thanks for explanation about baselines--that was very helpful in straightening out cosmetic issues I was seeing. I don't see in your code where page numbering issue is dealt with: can you point that out please? As to using gobble, tex.ac.uk/FAQ-nopageno.html seems to consider it an acceptable means of foregoing page numbering--"An alternative (in all classes) is to use the rather delightful \pagenumbering{gobble}; this has the simple effect that any attempt to print a page number produces nothing, so there’s no issue about preventing any part of LaTeX from printing the number." – MJiller Dec 28 '17 at 2:14
  • Tried this MWE and it does work fine. Definitely a good solution for doing the sort of thing at which I'm aiming. I did have to increase the top margin a bit to push the center heading down a little further--not sure why the two recipes give differing results here. I decided to just stick with the MWE I gave above and just make certain I keep the same number of items in left and right headings so everything's aligned. Thanks much for your input cfr – MJiller Jan 2 '18 at 21:12
  • @MJiller Some things need page numbers, so it is better to not print them than gobbling them. \fancyhf{} clears all header and footer content from the fancy page style, so you start with nothing and just get whatever you add. I always use this when using fancy styling. Otherwise, you are just adding stuff, which I guess is fine if that's what you want but less great otherwise. just clear everything before defining your headers and footers and you'll get what you want. – cfr Jan 6 '18 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.