5

I would like to locate the exact position of the north west corner of the text area. Using \layout (see image in Notes section), it seems that the required offset from current page.north west is

xshift=1.0in+\hoffset+\oddsidemargin,
yshift=-1.0in-\voffset-\headsep,

Using showframe package: (as in MWE)

The image below is the north west corner of the text area at 6400% zoom where I have placed a gray + and a filled in circle. This visually looks like it is pretty close to the correct location. However, to get to this position required an additional tweak of

(-0.35pt,2.35pt)%% Required shift to obtain image below (see MWE)

from the above parameters.

The somewhat related questions listed in the References section mention an issue with inner sep and \parindent, both of which have been accounted for. (They are actually not needed here, but added them anyway).

Why is this additional tweak required?

enter image description here

Using showframe option to geometry package:

IF instead of using the showframe package, I instead use

\usepackage[showframe]{geometry}

The tweak required is slightly different:

(-0.1pt,1.8pt)

which yields:

enter image description here

References:

Notes:

  • Using \layout, we obtain the following picture from which I obtained the parameters to compute the exact location of the north west of the text area.

    enter image description here

    enter image description here

Code:

\documentclass{article}
\usepackage{showframe}
\usepackage{tikz}

\usepackage{layout}
\usepackage{geometry}

\newcommand*{\ShowNorthWestOfTextArea}{%
\begin{tikzpicture}[remember picture, overlay]
    \coordinate (X) at ([
            xshift=1.0in+\hoffset+\oddsidemargin-0.35pt,
            yshift=-1.0in-\voffset-\headsep+2.35pt,
        ]current page.north west);

    \draw [draw=red, fill=yellow, text=gray] (X) circle (1pt)
        node [inner sep=0pt] {+};
\end{tikzpicture}%
}%


\begin{document}%\layout% <-- uncomment to obtain the layout parameters
\noindent\ShowNorthWestOfTextArea%
\end{document}
  • 1
    Does tikzpagenodes help? Specifically, once it is loaded you can use (current page text area.north west). – Andrew Dec 4 '18 at 0:01
  • Actually, loading tikzpagenodes and doing \tikz[overlay,remember picture]{ \draw [draw=red, fill=yellow, text=gray] (current page text area.north west) circle (1pt) node [inner sep=0pt] {+};} seems to indicate that the frame is around the text area, meaning that the line is outside and your mark is already a tiny bit outside the text area, precisely by the additional shift. – marmot Dec 4 '18 at 0:06
  • @Andrew: Yep, tikzpagenodes seems to do the correct position without any tweaks, so that is definitely the solution to use instead of computing it directly. I'd still be interested in what is going on though. Seems to imply some issue with either showframe package (and showframe option to geometry) or a deficiency with the layout package. – Peter Grill Dec 4 '18 at 0:13
  • @PeterGrill I really think it is the line width. The frame is drawn in such a way that the line is completely outside the text area, but the inner boundary of the frame is the outer boundary of the text area. You place your mark in the middle of the line. – marmot Dec 4 '18 at 0:16
  • 1
    @marmot: Agreed. BTW, not sure if you noticed but I updated the question: seems as if you use the showframe option to the geometry package, the line width is a more reasonable. – Peter Grill Dec 4 '18 at 0:28
4

Position of the text area relative to the page corner

The top of the \layout image generally looks like the image below, but in your case the dashed line appears to coincide with the bottom of the header because ④ (\topmargin = -13pt) and ⑤ (\headheight = 12pt) nearly cancel out.

distances

You can read off that the horizontal/vertical distance between the top left corner of the text with respect to the top left corner of the page are

horizontal distance = 1in+\hoffset+\oddsidemargin or 1in+\hoffset+\evensidemargin,
vertical distance = 1in+\voffset+\topmargin+\headheight+\headsep

(\oddsidemargin is for single-sided documents and odd pages of double-sided documents, and \evensidemargin for even pages of double-sided documents.)

Position of the text area relative to current page.north west

For TikZ, the coordinates of the top left corner of the text area are (w.r.t. current page.north west)

(1in+\oddsidemargin, -1in-2\voffset-\topmargin-\headheight-\headsep)

for a single-sided document and odd pages of double-sided documents (and the same with \evensidemargin for even pages of a double-sided document).

Note: I have no clue why you would need to add -2\voffset to the y coordinate, but it seems like a bug. Perhaps a sign error was made somewhere in the code when correcting for \voffset?

Usually \hoffset and \voffset are both equal to zero, however, so this won't matter.

Here is a version of your MWE with the right parameters:

\documentclass{article}
\usepackage{showframe}
\usepackage{tikz}

\usepackage{geometry}

\newcommand*{\ShowNorthWestOfTextArea}{%
\begin{tikzpicture}[remember picture, overlay]
    \coordinate (X) at ([
            xshift=1.0in+\oddsidemargin,
            yshift=-1.0in-2\voffset-\topmargin-\headheight-\headsep,
        ]current page.north west);

    \draw [draw=red, fill=yellow, text=gray] (X) circle (1pt)
        node [inner sep=0pt] {+};
\end{tikzpicture}%
}%

\begin{document}

\noindent\ShowNorthWestOfTextArea%

\end{document}

output

Note that showframe draws a border around the text area.

  • Any idea why \layout with \usepackage{layout} in your MWE does not produce the layout image you show? – Peter Grill Dec 4 '18 at 18:26
  • The appearance of \layout depends on the lengths it is illustrating. The horizontal dashed line appears below the top of the header because the geometry package sets topmargin to a negative value. The word "should" was probably not appropriate in the first paragraph. – Circumscribe Dec 4 '18 at 18:35
  • Oh that makes sense. I guess the \layout package should check to see if geometry is loaded and adult the drawing appropriately -- Or at least check if the parameters are set such that it is difficult to draw a useful layout. – Peter Grill Dec 4 '18 at 18:43
2

The package tikzpagenodes provides a useful set of tikz coordinates for:

  • current page text area
  • current page marginpar area
  • current page header area
  • current page footer area

So, if tikzpagenodes is loaded then you can get the "north west corner of the text area" using (current page text area.north west) from inside a tikzpicture environment. You will need to use remember picture,overlay for this to work.

Adapting the MWE from the question, we can use:

\documentclass{article}
\usepackage{showframe}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usepackage{layout}
\usepackage{geometry}

\newcommand*{\ShowNorthWestOfTextArea}{%
\begin{tikzpicture}[remember picture, overlay]
  \coordinate (X) at (current page text area.north west);

  \draw [draw=red, fill=yellow, text=gray] (X) circle (1pt)
      node [inner sep=0pt] {+};
\end{tikzpicture}%
}%


\begin{document}%\layout% <-- uncomment to obtain the layout parameters
  \ShowNorthWestOfTextArea%
\end{document}

With this code, the north west corner of the text area looks like:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.