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.

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?

share|improve this question
    
I'd probably use TikZ to add a node at the given point; with the y-coordinate of this point and the y coordinate of, for example, current page.center you could calculate the length that you want. –  Gonzalo Medina Dec 2 '11 at 4:00
    
Have a look at the similar question How to define a figure size so that it consumes the rest of a page?. It's solution can be tweaked to give you the length you need. –  Martin Scharrer Dec 2 '11 at 9:29

1 Answer 1

up vote 11 down vote accepted

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").

share|improve this answer
    
Very good solution, showing both approaches. Shouldn't 1em, be 10pt though? The default for article? –  Yiannis Lazarides Dec 2 '11 at 16:21
    
@YiannisLazarides: Probably - I wasn't sure where to find the first \baselineskip on a page. Any source? –  Werner Dec 2 '11 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:). –  Yiannis Lazarides Dec 2 '11 at 19:18

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.