0

I want to draw a picture just at the upper left corner of a page with Tikz. But the picture I draw with the following code fails to be at the right position as shown in the attached figure. Why, and how to deal with it?

CODE:

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

\begin{document}

\begin{tikzpicture}[remember picture,overlay]
\path [inner sep=0,,outer sep=0pt,line width=1mm,opacity=.25,draw=red,fill=blue,scale=2]
(current page.north west) (0,0)--(2,0)--(2,-2)--(0,-2)--cycle;
\end{tikzpicture}

% Contrast with current page.south west
\begin{tikzpicture}[remember picture,overlay]
\node [xshift=0cm,yshift=0cm] at (current page.south west)
[text width=7cm,fill=red!20,rounded corners,above right]
{
This is an absolutely positioned text in the
lower left corner. No shipout-hackery is used.
};
\end{tikzpicture}

\end{document}

enter image description here

3
  • 3
    [shift=(current page.north west)]. Otherwise you are just moving to the corner point and immediately move back to (0,0), as it is the next moveto command.
    – Symbol 1
    Jul 10, 2021 at 1:53
  • Would you give more info about moveto? And why does \node in my second part of the code not need shift?
    – lyl
    Jul 10, 2021 at 7:55
  • 1
    With [overlay] the origin is placed at the current location (baseline) in the text area. Think of the tikzpicture as \hbox{}:, invisible but there. Jul 10, 2021 at 13:20

1 Answer 1

2

I can't answer why, but my guess would be that tikz defaults the bounding box of any image to the text area.

As mentioned in the comments (current page.north west) is a coordinate similar to how (0,0) is a coordinate. Your draw command uses absolute positioning and there is no line drawn starting at (current page.north west). This is different from your node which is positioned using the at notation.

So you can basically use the coordinate and then relative positioning of your coordinates using the ++ notation:

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

\begin{document}
    \begin{tikzpicture}[remember picture,overlay]
        \path [inner sep=0,,outer sep=0pt,line width=1mm,opacity=.25,draw=red,fill=blue,scale=2]
        (current page.north west) -- ++(2,0) -- ++(0,-2) -- ++(-2,0) -- cycle;
    \end{tikzpicture}
\end{document}

You must log in to answer this question.

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