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?
Asked
Active
Viewed 1,653 times
17
1 Answers
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:

\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").
-
Very good solution, showing both approaches. Shouldn't 1em, be 10pt though? The default for article? – yannisl Dec 02 '11 at 16:21
-
@YiannisLazarides: Probably - I wasn't sure where to find the first
\baselineskipon a page. Any source? – Werner Dec 02 '11 at 16:24 -
no it was off the top of my head:). Your calculation is correct, however
\pagetotalmeasures from the top of the page (which includes\topskip) - not as you indicated. The correction for the rule height is to addbaselineskip-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 02 '11 at 19:18 -
This doesn't work for me;
pagetotalis always 0 (using beamerposter in beamer) – Clément Sep 16 '14 at 13:58
current page.centeryou could calculate the length that you want. – Gonzalo Medina Dec 02 '11 at 04:00