5

Consider this MWE:

\documentclass{scrartcl}
\begin{document}
\hrule
Paragraph

\vspace*{1cm}

\hrule
\smash{~~~~~~~~~~~~~~~~Overlap}
Paragraph
\end{document}

(View output at latexfiddle.com)

In the first bit, the \hrule is touching the Paragraph, as it should.

Now I am inserting something that is \smash’ed in between, hoping that it would not affect the vertical placing, but it does: A small space appears between the rule and the text.

Why? And how do I avoid it?

2
  • There is the interline space between the hbox produced with \smash and the following paragraph. Add \nointerlineskip after the \smash
    – egreg
    Oct 19, 2015 at 14:30
  • Another way: \hspace*{4cm}\makebox[0pt]{\smash{Overlap}}% \hrule Paragraph.
    – user11232
    Oct 19, 2015 at 14:33

1 Answer 1

6

If you say

\hbox{x}
\hbox{y}

when in vertical mode, TeX will add interline glue between the boxes. The same if you say

\setbox0=\hbox{x}\box0
Paragraph

because at the end the two things are the same. What \smash does is, essentially, setting an \hbox and clearing its height and depth, then doing \box0. Thus what you see between the rule and “Paragraph” is actually the interline glue between the smashed text and “Paragraph”.

Solution: add \nointerlineskip:

\documentclass{scrartcl}
\begin{document}
\hrule
Paragraph

\vspace*{1cm}

\hrule
\smash{~~~~~~~~~~~~~~~~Overlap}\nointerlineskip
Paragraph
\end{document}

enter image description here

UPDATE

Due to changes in the LaTeX kernel, \smash now “leaves vertical mode”. Thus, in order to avoid a paragraph to be started by it, one has to enclose it in \hbox:

\documentclass{scrartcl}
\begin{document}
\hrule
Paragraph

\vspace*{1cm}

\hrule
\hbox{\smash{~~~~~~~~~~~~~~~~Overlap}}\nointerlineskip
Paragraph
\end{document}
2

You must log in to answer this question.

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