# Prelim2e marking but centred without tikz

I use preliminary markup on draft versions of documents which specifies the svn repository number, timestamp, url etc. I prefer this to be typeset centred at the bottom of the page below the footer.

Here is the effect I am trying to achieve:

The solution needs to:

• work in both onecolumn and twocolumn mode;
• work with at least the standard LaTeX classes;
• work with geometry and fancyhdr;
• allow LaTeX commands in the specification of the preliminary marker so I can typeset svn information, \today etc. and allow multi-line markers;
• centre the marker beneath the footer but within the printable area even when different options are passed to geometry and fancyhdr;
• be sensitive to whether the draft or final option is active;
• not affect page layout in other ways e.g. it must not affect page or line breaks, alignment or placement of the header/footer;
• work with pdfLaTeX.

I have been using prelim2e. However, this does not centre the marking beneath the footer consistently or correctly. This prompted me to ask this question. Although there is something odd about geometry's effect there, it seems that there is also a distinct issue with prelim2e in the sense that no matter what I try, I cannot get the markup centred beneath the footer. This is true even if I stick to the very simplest configuration and just try something like \PrelimWords{a}.

After searching this site and ctan for a bit, I came across maetra's comment on this answer. That comment suggests combining background and ifdraft. So I tried the following:

\documentclass[draft,twocolumn]{article}
\usepackage{url,svn-multi}
\svnidlong
{$HeadURL: file:///svn/myproject/tweaked-branch/usr/local/texlive/current/texmf-dist/tex/latex/something/something.sty$}
{$LastChangedBy: cfr$}
{$LastChangedRevision: 19567$}
{$LastChangedDate: 2014-04-16 19:46:05 +0100 (Mer, 16 Ebr 2014)$}
\usepackage[hscale=.875]{geometry}
\usepackage{ifdraft}
\makeatletter
\ifdraft{%
\usepackage[placement=bottom,scale=1,opacity=1,vshift=10mm]{background}
\newsavebox{\prelimtxt}
\sbox{\prelimtxt}{%
\parbox{\textwidth}{%
\urlstyle{sf}%
\centering \small \textsf{Draft --- \today\ --- Revision \svnrev\ --- \svnyear--\svnmonth--\svnday\ \svnhour:\svnminute:\svnsecond}\\[1em]
}% end parbox
}% end sbox
\backgroundsetup{contents=\usebox{\prelimtxt}}
}{\backgroundsetup{contents={\centering \small \textsf{Draft --- pdf\LaTeX{}ed --- \today}}}}}{%
\providecommand{\pgfsyspdfmark}[3]{\relax}}
\makeatother
\usepackage{kantlipsum}
\begin{document}
\kant[1-5]
\end{document}


Although I have not yet tried this in a real document, the results appear to be exactly what I'm looking for. The output is, in fact, that I posted above.

However, it does seem to be a sledgehammer to crack a nut. This solution requires me to load tikz merely to set the preliminary marker at the bottom of the page. I realise this is because background is much more powerful and flexible than prelim2e and I really like the package for other uses. It just feels like overkill here. (Note that much of my customisation is dedicated to undoing the doings of background by setting the scale back to 1, using full opacity etc.)

Moreover, this solution requires me to either put up with errors when switching to final or to load tikz even when I'm not using it at all. (My code above institutes a hack to avoid both evils which involves just setting a dummy command if necessary.)

Is there an alternative solution which works properly but is a bit lighter weight? Or a workaround for prelim2e (seems doubtful from what I've read)?

• I was using picture environment to move a wanted material to a new position on page, but it is relative positioning, it needed a fixed point. I was thinking about zwpagelayout package for a minute but it primarily focuses on crop marks. I would be thinking about pst-abspos and textpos packages, but you are trying to avoid them. I jumped from current fixed position to page center in tex.stackexchange.com/questions/171500/… – Malipivo Apr 18 '14 at 5:01
• @Malipivo Although it doesn't seem to like the landscape environment. Also, I had to fiddle a bit to get it to work with other things. I guess one can't have everything... ;) – cfr Apr 18 '14 at 18:51
• Please try pdflscape package, or, try \pdfpagewidth=\paperwidth and \pdfpageheight=\paperheight directly at some point before calculations. It usually costs me a headache. – Malipivo Apr 18 '14 at 19:01
• @Malipivo I suspect I'll just live with it. I already use pdflscape and the calculations are done at the beginning of the document whereas I'm then screwing it up by setting a particular page in landscape. prelim2e somehow manages this but I think I might just set the pagestyle to empty! Thanks, though. – cfr Apr 18 '14 at 19:12

Thanks to Malipivo's comment, I thought that I might try using eso-pic directly. This is the package prelim2e uses but I wondered if the placement problems might be an artefact of prelim2e rather than a problem with the underlying framework provided by eso-pic itself. After playing with this for a little, things started to go better...

This solution uses eso-pic, calc and ifdraft but does not require background or, therefore, tikz. It works with pdfLaTeX (not just LaTeX), centres the preliminary marker at the bottom beneath the footer and should not affect the layout, page or line breaking. It works with geometry, fancyhdr, both onecolumn and twocolumn, and is sensitive to the final/draft option thanks to ifdraft.

I'm sure there's a catch somewhere but the MWE looks good...

\documentclass[draft,twocolumn,a4paper]{article}
\usepackage{url,svn-multi}
\svnidlong
{$HeadURL: file:///svn/myproject/tweaked-branch/usr/local/texlive/current/texmf-dist/tex/latex/something/something.sty$}
{$LastChangedBy: cfr$}
{$LastChangedRevision: 19567$}
{$LastChangedDate: 2014-04-16 19:46:05 +0100 (Mer, 16 Ebr 2014)$}
\usepackage{ifdraft}
\makeatletter
\AtBeginDocument{%
\ifdraft{%
\usepackage{eso-pic}
\usepackage{calc}
\newsavebox{\prelimtxt}
\sbox{\prelimtxt}{%
\parbox[t]{\textwidth}{%
\urlstyle{sf}%
\centering
\sffamily
\small
Draft --- \today\ --- Revision \svnrev\ --- \svnyear--\svnmonth--\svnday\ \svnhour:\svnminute:\svnsecond\\[.5em]
\tiny
}% end parbox
}% end sbox
}{%
\sbox{\prelimtxt}{%
\parbox[t]{\textwidth}{%
\centering \small \textsf{Draft --- pdf\LaTeX{}ed --- \today}%
}% end parbox
}% end sbox
\begingroup
\settototalheight{\@tempdima}{\usebox{\prelimtxt}}%
\setlength{\@tempdimb}{.5\paperwidth-.5\textwidth}%
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdimc}){%
\usebox{\prelimtxt}}%
\endgroup
}{}% end ifdraft
}
\makeatother
\usepackage[hscale=.875]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[lh]{\emph{Immanuel Kant}}
\fancyhf[rh]{\emph{My Musings}}
\fancyhf[cf]{\emph{--- \thepage ---}}
\usepackage{kantlipsum}
\begin{document}
\kant[1-5]
\end{document}


The code below deals, I think, with the case where the landscape environment is used to typeset selected pages in landscape orientation. The code has showframe set for geometry and this gives an extremely puzzling result on page 2 (which is landscape). This is pretty horrible, in any case. Is there really no better solution than mine?!

\documentclass[draft,a4paper]{article}
\usepackage{url,svn-multi}
\svnidlong
{$HeadURL: file:///svn/myproject/tweaked-branch/usr/local/texlive/current/texmf-dist/tex/latex/something/something.sty$}
{$LastChangedBy: cfr$}
{$LastChangedRevision: 19567$}
{$LastChangedDate: 2014-04-16 19:46:05 +0100 (Mer, 16 Ebr 2014)$}
\usepackage{ifdraft}
\usepackage{pdflscape}
\makeatletter
\AtBeginDocument{%
\ifdraft{%
\usepackage{eso-pic}
\usepackage{calc}
\newlength{\origtextwidth}%
\newlength{\origtextheight}%
\setlength{\origtextwidth}{\textwidth}%
\setlength{\origtextheight}{\textheight}%
\newsavebox{\prelimtxt}
\sbox{\prelimtxt}{%
\parbox[t]{\textwidth}{%
\urlstyle{sf}%
\centering
\sffamily
\small
Draft --- \today\ --- Revision \svnrev\ --- \svnyear--\svnmonth--\svnday\ \svnhour:\svnminute:\svnsecond\\[.5em]
\tiny
}% end parbox
}% end sbox
}{%
\sbox{\prelimtxt}{%
\parbox[t]{\textwidth}{%
\centering \small \textsf{Draft --- pdf\LaTeX{}ed --- \today}%
}% end parbox
}% end sbox
\begingroup
\settototalheight{\@tempdima}{\usebox{\prelimtxt}}%
\setlength{\@tempdimb}{.5\paperwidth-.5\origtextwidth}%
\put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdimc}){%
\usebox{\prelimtxt}}%
\endgroup
}{}% end ifdraft
}
\makeatother
\usepackage[hscale=.875,showframe]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[lh]{\emph{Immanuel Kant}}
\fancyhf[rh]{\emph{My Musings}}
\fancyhf[cf]{\emph{--- \thepage ---}}
\usepackage{kantlipsum}
\begin{document}
\kant[1-5]
\begin{landscape}
\kant[6-10]
\end{landscape}
\kant[11-20]
\end{document}


This was prompted by Malipivo's comment that \textwidth=\textheight within the landscape ship out environment. This is illustrated by the frame on page 2 above. The only way I could figure out to place the markings correctly despite this was to save the lengths at the beginning of the document in macros for use as constants in the ship out environment. (I also tried modifying the landscape environment. Although that works I don't think it has any benefit.)

• Well done! I tried landscape (paper) and it looks fine. I will try landscape env. in a minute... – Malipivo Apr 18 '14 at 19:23
• @Malipivo Thanks! I'm not entirely satisfied. Apart from the landscape thing, I'm not convinced I'm calculating the vertical placement correctly. (There's no pleasing some people - first I complain about the horizontal, now I moan about the vertical.) I tried using geometry's layout diagrams but it doesn't end up where I think it should. [I wanted it to always be equidistant from the bottom of the footer and the bottom of the page but it doesn't seem to work - not quite - so I must have misunderstood somewhere.) – cfr Apr 18 '14 at 20:15
• I am measuring \textwidth and \textheight as equal inside the \AddToShipoutPictureBG command, that's strange and geometry is not to be blamed, it is turned off. It is probably causing eso-pic. There is worse thing/bug, when I use \usepackage[hscale=.875]{geometry} then in landscape environment I am completely losing the second and following pages in that environment. – Malipivo Apr 18 '14 at 21:02
• @Malipivo Hmmm... How do you find out what the values are within \AddToShipoutPictureBG? – cfr Apr 18 '14 at 23:15
• I am using \typeout{\the\textwidth, \the\textheight, \the\pdfpagewidth, \the\pdfpageheight}. After that I can read dimensions from the terminal. – Malipivo Apr 19 '14 at 5:12

Since the OP realized there is a known issue known as a "design comprimise" between lscape/pdflscape and the geometry packages (I know Zdeněk Wagner, the author of the zwpagelayout package, in person, I would use his package instead of geometry under normal circumstances), I tried to find another strategy even if I like shifting from the fixed position very much.

I put all the information right below the page number directly by redefining the footer center using the fancyhdr package. I neither need eso-pic nor calc packages anymore. It is working well, but we are losing the last page in the landscape environment. It is working again if we change either:

• \usepackage[hscale=.875]{geometry} to \usepackage{geometry}, or,
• we turn off twocolumn parameter in the line with \documentclass.

I found a patch to this: let's use \onecolumn before \begin{landscape} and \twocolumn after \end{landscape}. It improved things a lot, but there is still one issue to be solved that we don't have two columns in the landscape environment, yet. We could try \twocolumn inside this environment but we would get two columns on top of each other. Therefore I turned on the multicol package and here we are.

I enclose an example and a preview of 8 pages, we can run any major latex engine. It works with lscape and pdflscape packages.

% run: *latex mal-hsize.tex
\documentclass[draft,twocolumn,a4paper]{article} % draft twocolumn
\usepackage[hscale=.875]{geometry} %[hscale=.875]
\usepackage{multicol}
\usepackage{pdflscape}
\usepackage{url}
\usepackage{svn-multi}
\ifx\svnidlong\undefined
\relax
\else
\svnidlong
{$HeadURL: file:///svn/myproject/tweaked-branch/usr/local/texlive/current/texmf-dist/tex/latex/something/something.sty$}
{$LastChangedBy: cfr$}
{$LastChangedRevision: 19567$}
{$LastChangedDate: 2014-04-16 19:46:05 +0100 (Mer, 16 Ebr 2014)$}
\fi

\def\measureme{%
\scrollmode % show me information...
\typeout{%
page: \thepage^^J%
textwidth and textheight: \the\textwidth, \the\textheight,^^J%
pdfpagewidth and pdfpageheight: \the\pdfpagewidth, \the\pdfpageheight%
}% End of \typeout...
\batchmode % don't show me new information...
}% End of \measureme...

\usepackage{ifdraft}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[lh]{\emph{Immanuel Kant}}
\fancyhf[rh]{\emph{My Musings}}
%\fancyhf[cf]{\emph{--- \thepage ---}}

\ifdraft{%
\newbox\malbox
\ifx\svnidlong\undefined
\setbox\malbox=\hbox{%
\parbox[t]{\textwidth}{%
\centering \small \textsf{Draft --- pdf\LaTeX{}ed --- \today}%
}% End of \parbox...
}% End of \setbox...
\else
\setbox\malbox=\hbox{%
\parbox[t]{\textwidth}{%
\urlstyle{sf}%
\centering
\sffamily
\small
Draft --- \today\ --- Revision \svnrev\ --- \svnyear--\svnmonth--\svnday\ \svnhour:\svnminute:\svnsecond\\[.5em]
\tiny
}% End of \parbox...
}% End of \setbox...
\fi
\fancyfoot[C]{\measureme\emph{--- \thepage\ --- \\[9pt] \copy\malbox}%
}%
}{\relax}% End of \ifdraft...
\usepackage{kantlipsum}

\begin{document}
\kant[1-7]

\onecolumn % a patch, part 1
\begin{landscape}
%\twocolumn :-)
\begin{multicols}{2}
\kant[6-26]
\end{multicols}
\end{landscape}
\twocolumn % a patch, part 2

\kant[1-7]
\end{document}


• +1 for such a detailed and careful answer. I'd never heard of zwpagelayout but it seems to be a really interesting package. (geometry is probably easier to use for my purposes but that's a different story.) I'm not sure what the best approach is right now. I actually created this problem in the first place by attempting to move away from multicols (which was part of my previous solution) because of its limitations in handling floats. This is one of those cases in which I feel that every time I fix one problem, I create another... – cfr Apr 19 '14 at 14:48
• I see, I usually escape multicols environment, place floating bodies in the document and return to the multicols environment. But this area is quite complex, it depends a lot on the actual problem. – Malipivo Apr 19 '14 at 14:53