[Tex/LaTex] “! You can’t use `\raise’ in internal vertical mode” error

errorstex-core

I used the command \raise to superimpose a title to a writing.

I got the error

! You can't use `\raise' in internal vertical mode

which puzzled me for a while.

For those interested, here is my code :

\def\withHatTitle#1#2{% #1: title #2: content
\setbox1=\hbox{#2}
\setbox0=\hbox{%\leaders\hrule height3pt depth-2pt\hskip 5pt
\kern\fboxsep#1\kern\fboxsep\leaders\hrule height3pt depth-2pt\hskip 5pt}
\ifdim\wd1<\wd0\wd1=\wd0\fi% if title longer than content, title gives the size
\setbox0=\hbox{\makebox[\wd1]{\box0\leaders\hrule height3pt depth-2pt\hfill}}% complete title with hrule
\wd1=0pt \box1 \raise 11pt \box0}% superpose title and content

Best Answer

The explanation for this error is that \raise is forbidden in vertical mode, that is roughly when Tex piles up boxes in vertical.

Thus, the solution is simple : exit from the vertical mode. A simple solution consists in enclosing my macro \withHatTitle with a \hbox command, as follows:

\hbox{\withHatTitle{The title}{This is the text to be titled}}

Hope this helps !

P.S. the former is true also with \lower.

Related Question