7

The horizontal bar from the following MWE does not start at the left edge of the paper as expected, but rather a bit more to the right. The line is 17cm long and the page width is also 17cm, which results in the warning

Overfull \hbox (1.59978pt too wide) in paragraph at lines 9--10

I tried adding '%' signs at the end of all the lines without any effect. What am I missing please?

\documentclass{article}
\usepackage[a4paper, showframe, margin=2cm]{geometry}
\usepackage{tikz}
\setlength{\parindent}{0pt}

\begin{document}
\begin{tikzpicture}
\draw[ultra thick] (0,0) -- (17,0);
\end{tikzpicture}
\end{document}

screenshot

1 Answer 1

8

You are not missing anything; apparently TikZ adds some padding equal to the line width (you can see this by using different values for line width in your \draw). You can prevent the undesired space using the overlay option (either globally for the whole tikzpicture, or locally for just the \draw):

\documentclass{article}
\usepackage[a4paper, showframe, margin=2cm]{geometry}
\usepackage{tikz}
\setlength{\parindent}{0pt}

\begin{document}

\begin{tikzpicture}
\draw[overlay,ultra thick] (0,0) -- (17cm,0);
\end{tikzpicture}

\end{document}

The result:

enter image description here

2
  • 1
    @cfr I believe this is only because of your node referencing current bounding box. This answer still produces the same output. However, the TikZ picture reports a box of zero size back to TeX. (It basically \smashes and \rlap the diagram.) Try Foo\tikz[overlay]\draw[ultra thick] (0,0) -- (17cm,0);Bar to see that more clearly. For a simple horizontal line on its own paragraph, this is okay. Commented Nov 16, 2023 at 21:45
  • @Qrrbrbirlbel I didn't realise TikZ had such a crazy bb to begin with. Thanks.
    – cfr
    Commented Nov 17, 2023 at 1:49

You must log in to answer this question.

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