8

Without \noindent, \rlap and \llap seem to move down by \baselineskip every time. Is this deliberate?

\documentclass{article}
\usepackage{xcolor}

\begin{document}
\color{red}
\rlap{\rule{.25in}{1ex}}\rlap{\rule{.25in}{1ex}}\rlap{\rule{.25in}{1ex}}

\color{blue}
\noindent\rlap{\rule{.25in}{1ex}}\rlap{\rule{.25in}{1ex}}\rlap{\rule{.25in}{1ex}}

\color{green}
\llap{\rule{.25in}{1ex}}\llap{\rule{.25in}{1ex}}\llap{\rule{.25in}{1ex}}

\color{black}
\noindent\llap{\rule{.25in}{1ex}}\llap{\rule{.25in}{1ex}}\llap{\rule{.25in}{1ex}}
\end{document}

color bars

3
  • My take on this is this: Without \noindent you're still in vertical mode, stacking horizontal boxes, hence the duplication of \rlap in the output. \noindent (like \leavevmode) starts a paragraph, where the horizontal boxes are overlaid due to the overlapping. – Werner Feb 21 '15 at 5:10
  • Piggy-backing on what @werner said, if you read section 16.3 of TeX by Topic, it'll explain what's happening. You've got to keep in mind that \rlap and \llap are both defined in terms of an \hbox. – A.Ellett Feb 21 '15 at 5:18
  • 2
    Use \makebox[0pt][l]{...} instead of \rlap and \makebox[0pt][r]{...} instead of \llap. Less efficient, perhaps, but safer also with respect to color changes. By the way, avoid \color commands between paragraphs. – egreg Feb 21 '15 at 9:35
9

Both \rlap and \llap are defined in terms of an \hbox

\def\rlap#1{\hb@xt@\z@{#1\hss}}
\def\llap#1{\hb@xt@\z@{\hss#1}}

where

\def\hb@xt@{\hbox to}

However, an \hbox cannot be used to start a paragraph. You either need to explicitly switch to horizontal mode by using something like \noindent or \leavevmode. (See section 16.3 of TeX by Topic for further details.)

Here's your MWE behaving a bit more like you probably expected it should:

\documentclass{article}
\usepackage{xcolor}
\newcommand\aelap[1]{\makebox[0pt][r]{#1}}
\begin{document}

\color{red}
\leavevmode\rlap{\rule{.25in}{1ex}}\rlap{\rule{.25in}{1ex}}\rlap{\rule{.25in}{1ex}}

\color{blue}
\noindent\rlap{\rule{.25in}{1ex}}\rlap{\rule{.25in}{1ex}}\rlap{\rule{.25in}{1ex}}

\color{green}
\leavevmode\llap{\rule{.25in}{1ex}}\llap{\rule{.25in}{1ex}}\llap{\rule{.25in}{1ex}}

\color{black}
\noindent\llap{\rule{.25in}{1ex}}\llap{\rule{.25in}{1ex}}\llap{\rule{.25in}{1ex}}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.