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.

I'm working on the TikZ-from-TeX-SX package, specifically developing the code for putting equation numbering at places within a tikzpicture environment. To do this, I need to know where the text starts and stops horizontally on the page. From looking at a couple of diagrams, it seems that the left-hand margin is at: \hoffset + 1in + \oddsidemargin (but that \oddsidemargin worries me somewhat!) and to get the right-hand margin I add \textwidth.

So the question: how do I reliably figure out where my left and right margins are (as measured from, say, the left-hand edge of the page)?

If it matters, then I'd rather go for where TeX thinks they are than where they actually are. Namely, if there's some grouping in which the user has changed a load of lengths that fool TeX temporarily, but where that fooling is over before TeX actually puts anything on the page, then I'll join TeX in its dream-world.

Also, I guess that knowing which page I'm on will be important. In which case, I'm allowed to have two TeX runs to figure it out since I already need two TeX runs for some other stuff in the package.

(Note: This question is absolutely nothing to do with TikZ)

share|improve this question

2 Answers 2

up vote 11 down vote accepted

\hoffset + 1in + \oddsidemargin + \leftskip and for right margin, add \textwidth - \rightskip.

For display material, there is also \displayindent and \displaywidth.

I should also mention the layout package.

share|improve this answer
    
Out of curiosity: where does that 1in come from? –  Caramdir Apr 23 '11 at 2:44
2  
@Caramdir: Knuth decided that \hoffset (resp. \voffset) of 0pt should be 1in from the left (resp. top) of the page. See section 26.1 in TeX by Topic. –  TH. Apr 23 '11 at 5:11
    
@Caramdir "\hoffset \voffset Distance by which the page is shifted right/down with respect to the reference point. It is a TEX convention, to which output device drivers must adhere, that the top left point of the page is one inch from the page edges. Unfortunately this may lead to lots of trouble, ...". I think it's not a good idea to use \hoffset \voffset, these macros are useful for a user who has a problem with a bad outpout device driver. It's useful to shift correctly the page at the final placement. –  Alain Matthes Apr 25 '11 at 10:31
    
If I start at the left margin, as you describe it, and then move to the right margin, should I also subtract \leftskip? So that in absolute terms, the right margin is at \hoffset + 1in + \oddsidemargin + \textwidth - \rightskip. –  Loop Space Jun 4 '11 at 21:35
    
@Andrew: Yep. I believe so. –  TH. Jun 4 '11 at 23:34

There is zref package to get a reference of the page layout, or the position of any text.

\documentclass{article}
\usepackage[user,pagelayout,savepos]{zref}

\begin{document}
\section{pagelayout}

During page shipout, \verb|\oddsidemargin| is
\zref[oddsidemargin]{thepage}sp. (You won't be fooled)

\section{savepos}

\zsavepos{leftanchor}\fbox{FOO}\zsavepos{rightanchor}

FOO begins at (\zposx{leftanchor}sp, \zposy{leftanchor}sp)
and ends at (\zposx{rightanchor}sp, \zposy{rightanchor}sp).
\end{document}
share|improve this answer

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.