1

I'm having a problem understanding the relationship between TikZ line width and its relation to tikzpagenodes.sty. (MacTeX2017, updated in the last week.) When I use tikzpagenodes.sty as shown below, the resulting line is drawn indented by the line width, which in turn causes an overfull \hbox by the amount of the line width. The problem goes away if I use remember picture,overlay but that puts the line immovably where I don't want it.

I'm sure I've missed something basic.

\documentclass{article}

\usepackage{tikzpagenodes}

\begin{document}

\parindent0pt

\noindent
\begin{tikzpicture}[remember picture,overlay]
\draw[line width=18pt] (current page text area.north west) -- (current page text area.north east);
\end{tikzpicture}

\vspace{0.15in}

$\uparrow$ With \verb+\draw[remember picture,overlay]+


\vspace{0.5in}

$\leftarrow$ Left margin. With \verb+\draw[]+ $\downarrow$

\noindent
\begin{tikzpicture}[]
\draw[line width=18pt] (current page text area.north west) -- (current page text area.north east);
\end{tikzpicture}


\end{document}

Example of draw, line width and pagenodes problem

sgmoye
  • 8,586

2 Answers2

2

When TikZ calculates the bounding box, it adds half the current line width around the coordinates to leave space for the lines. However, there is only a horizontal line here. Thus, the vertical spacing is correct, but the default line cap style is butt, not rect or round thus the space at the left and right is added, but is empty.

The following example fixes the bounding box at the end of environment tikzpicture:

\documentclass{article}

\usepackage{tikzpagenodes}

\begin{document}

\noindent
\begin{tikzpicture}[remember picture,overlay]
  \draw[line width=18pt]
    (current page text area.north west) --
    (current page text area.north east)
  ;
\end{tikzpicture}

\vspace{0.15in}

$\uparrow$ With \verb+\draw[remember picture,overlay]+


\vspace{0.5in}

$\leftarrow$ Left margin. With \verb+\draw[]+ $\downarrow$

\noindent
\begin{tikzpicture}
  \draw[line width=18pt]
    (current page text area.north west) --
    (current page text area.north east)
  ;
  % Fix bounding box
  \path
    (current bounding box.south west) ++(9pt, 0) coordinate (ll)
    (current bounding box.north east) ++(-9pt, 0) coordinate (ur)
    \pgfextra{\pgfresetboundingbox}
    (ll)
    (ur)
  ;
\end{tikzpicture}
\end{document}

Result

Heiko Oberdiek
  • 271,626
0

A tikzpicture with [remember picture,overlay] does not take up horizontal space, but it does have a location. Specifically (0,0) will be located at the baseline wherever the tikzpicture is positioned.

\documentclass{article}

\usepackage{tikzpagenodes}

\begin{document}

\parindent0pt

$\downarrow$ With \verb+\draw[remember picture,overlay]+

\noindent
\begin{tikzpicture}[remember picture,overlay]
\coordinate (origin) at (0,0);
\draw[line width=18pt] (current page text area.west |- origin) -- (current page text area.east |- origin);
\end{tikzpicture}

\end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120