17

How can I obtain a measurement from the baseline of any line of text in a document to top of the body of text on a page?

3

1 Answer 1

15

The length \pagetotal is a measure of the accumulated distance from the baseline of the first line of the page. Alternatively, the zref package also allows node placement and coordinate extraction via its savepos module. For example:

enter image description here

\documentclass{article}
\usepackage[showframe]{geometry}% http://ctan.org/pkg/geometry
\usepackage[savepos]{zref}% http://ctan.org/pkg/zref
\newcounter{parcnt} \newcommand{\nl}{\stepcounter{parcnt}\theparcnt}
\begin{document}
\zsavepos{top}\nl\ \the\pagetotal \par
\nl\ \the\pagetotal \par \bigskip \bigskip
\nl\ \the\pagetotal \par
\nl\ \the\pagetotal \par \medskip
\nl\ \the\pagetotal \par
\nl\ \the\pagetotal \par \smallskip \smallskip \smallskip
\nl\ \the\pagetotal \par
\nl\ \the\pagetotal \par \vspace{2cm}
\zsavepos{bottom}\nl\ \the\pagetotal\ \the\dimexpr\zposy{top}sp-\zposy{bottom}sp\relax \quad%
  \smash{\rule{1pt}{\dimexpr\pagetotal+1em\relax}}
\end{document}

Both the \pagetotal and zref-labels identify a 191.84995pt vertical distance to the first base line. As such, I assume \dimexpr\pagetotal+1em\relax is what you're after (here 1em, from a visual standpoint, seemed to represent the first "\baselineskip").

4
  • Very good solution, showing both approaches. Shouldn't 1em, be 10pt though? The default for article?
    – yannisl
    Dec 2, 2011 at 16:21
  • @YiannisLazarides: Probably - I wasn't sure where to find the first \baselineskip on a page. Any source?
    – Werner
    Dec 2, 2011 at 16:24
  • no it was off the top of my head:). Your calculation is correct, however \pagetotal measures from the top of the page (which includes \topskip) - not as you indicated. The correction for the rule height is to add baselineskip-depth (this is more or less the font size or 1em). This will get affected in certain cases with topskip. Was hoping you could shed a bit more light:).
    – yannisl
    Dec 2, 2011 at 19:18
  • This doesn't work for me; pagetotal is always 0 (using beamerposter in beamer)
    – Clément
    Sep 16, 2014 at 13:58

You must log in to answer this question.

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