9

I've got some complex code giving me an error: ! You can't use '\vadjust' in vertical mode.

So I presume I need to switch to the horizontal mode. I've found this question, "What are vertical and horizontal modes?", but nothing explaining how to switch between them.

I've looked at the TeXbook, but nothing seems to answer this question.

How do switch between the two?

3
  • You don't want to switch to horizontal mode in order to use \vadjust; just say \ifvmode<...>\else\vadjust{<...>}\fi.
    – egreg
    Commented Jul 26, 2013 at 14:02
  • @egreg If I do the \ifvmode it ends up skipping the code which is supposed to typeset some numbers properly vertically spaced.
    – McGafter
    Commented Jul 26, 2013 at 14:06
  • 3
    Sorry, but without seeing the code it's impossible to say more. But \vadjust is for adding vertical material when we're in horizontal mode, so I can't understand why you need to use it in the first place. However, the way to ensure being in horizontal mode (which starts a paragraph, if issued in vertical mode) is \leavevmode.
    – egreg
    Commented Jul 26, 2013 at 14:09

1 Answer 1

14

The command \vadjust can be issued only in horizontal or inline math mode. Its purpose is to insert vertical material (for instance a vertical space) after the line where the command eventually ends up.

An example of \vadjust in LaTeX is given by \vspace that does (in the normal variant)

\ifvmode
  \vskip#1\vskip\z@skip
\else
  \@bsphack
  \vadjust{\@restorepar\vskip#1\vskip\z@skip}%
  \@esphack
\fi

Thus it just does a \vskip if already in vertical mode or it inserts a \vadjust item.

Sometimes \vadjust is used for “cheating”; an example is to add something to the left or right of a line without resorting to \marginpar. In this cases, horizontal mode must be ensured, which is obtained by issuing

\leavevmode

before \vadjust.

You must log in to answer this question.

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