4

The following MWE displays my problem. If I tex it twice I get two pages. The text on the two pages do not begin from the same vertical distance from the top of the page. So it appears that 9. (which happens to be the start of page 2) is higher up the page than 1 as shown in the image composition below.

enter image description here

If the tikzpicture environment is commented out then it works.

Two questions:

1: What's going on here? I assumed that the options [remember picture,overlay] don't affect the rest of the page (whereas they obviously do)

2: How to best solve this issue of adding a logo on a page and not affect anything else?

\documentclass[12pt]{article}
\usepackage[demo]{graphicx}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west] at (current page.north west) {\includegraphics[height=3\baselineskip]{image.png}};
\end{tikzpicture}%

\begin{enumerate}
\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\end{enumerate}

\end{document}
Geoff
  • 2,637
  • You have a paragraph break between the zero-size box that is the tikzpicture and the start of the list. Should the logo be only on this one page? – Torbjørn T. Jan 16 '17 at 10:31
  • @TorbjørnT. Yes, the idea is to have the logo only on page 1. – Geoff Jan 16 '17 at 10:34

1 Answers1

6
  1. What's going on here?

    The problem is related to the way pages are built and the particular case in which the page starts with a list (enumerate in your case).

    The trick that TikZ overlay uses is to typeset all its contents in a box of zero width and height, so that the content of that box does not "take space" at TeX eyes, and thus it is "overlaped" on top of its surroundings.

    The problem is that, when a page starts, TeX is in "vertical mode" and even if you insert an empty box, this makes TeX to leave vertical mode, because this first box (even if empty) is considered the beginning of a new paragraph. You can produce the same effect by replacing your tikzpicture by a \leavevmode command.

    If the next tokens after that are part of a "regular" paragraph, there is no noticeable effect. Only, that first paragraphs begins with an empty box which does not alter the paragraph indentation or shape. However, if the next token after the empty box is a list (enumerate in your case), LaTeX inserts a vertical space to separate it from previous paragraph. Usually, when vertical space is the first thing appearing in a page, it is discarded, but it is not your case, since you already have a previous empty box, produced by TikZ.

  2. How to solve it?

    I tried including some \unskip before the enumerate or inside it, without results. I don't really understand what \unskip does, but apparently it has no effect once the empty box was added, so a different approach is required.

    The trick is to avoid issuing the tikz environment as the first thing in the page. Note that, since you are using absolute coordinates inside it, it doesn't really matters where you put the code, as long as it is executed before the current page is shipped out. You could put it after the first \item, for example.

    As a more general solution, you can use the package atbegshi which allows you to add code to a page when it is ready to be shipped out. The command \AtBeginShipoutFirst{} adds the code to the first page on the document. If you want the logo on every page use \AtBeginShipout{} instead. If you want it only in some particular pages, use \AtBeginShipoutNext{} on those pages.

Using this idea, your example will be:

\documentclass[12pt]{article}
\usepackage[demo]{graphicx}
\usepackage{atbegshi}
\usepackage{tikz}

\AtBeginShipoutFirst{
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west] at (current page.north west) {\includegraphics[height=3\baselineskip]{image.png}};
\end{tikzpicture}
}

\begin{document}

\begin{enumerate}
\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\item This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. This is some dummy text. 

\end{enumerate}
\end{document}

Resulting in:

Result

JLDiaz
  • 55,732