2

I have the following example, which draws a vertical line at the top of the paper:

\def\makeheadline{
  \setbox0=\hbox to 0pt{\hskip-1in\hskip15cm \vrule depth 3cm \hss}
  \ht0=0pt \dp0=0pt
  \vbox to 0pt{\vskip-1in \box0 \vss}
  % orignal \makeheadline follows
  \vbox to 0pt{\vskip-22.5pt
    \line{\vbox to 8.5pt{}\the\headline}\vss}\nointerlineskip}
Hello World!
\bye

Now I want to add an additional horizontal line. I tried it this way:

\def\makeheadline{
  \setbox0=\hbox to 0pt{\hskip-1in\hskip15cm \vrule depth 3cm \hss}
  \ht0=0pt \dp0=0pt
  \setbox0=\hbox to 0pt{\hskip-1in \hrule width 15cm \hss}
  \ht0=0pt \dp0=0pt
  \vbox to 0pt{\vskip-1in \box0 \vss}
  % orignal \makeheadline follows
  \vbox to 0pt{\vskip-22.5pt
    \line{\vbox to 8.5pt{}\the\headline}\vss}\nointerlineskip}
Hello World!
\bye

But this throws the error:

! You can't use `\hrule' here except with leaders.

Can anybody explain what is wrong with the hrule?

  • \vrule height 0.4pt width 15cm – egreg Feb 12 at 9:04
4

The primitive \hrule is a vertical command; when TeX encounters it, it switches to vertical mode, emitting \par if it is in (unrestricted) horizontal mode.

Because of this, it cannot appear inside \hbox.

To the contrary, \vrule is a horizontal command, so it triggers starting a paragraph if found in vertical mode.

In your case \vrule height 0.4pt width 15cm will do.

  • Why is it "except with leaders"? – errekak Feb 12 at 22:56
  • 1
    @errekak If you want to realize a horizontal rule with leaders, you need \leaders\hrule\hskip<skip>. – egreg Feb 12 at 22:59

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.