Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to replace \vspace with \addvspace in a command. When so doing, I get obtuse "something's wrong--perhaps a missing \item." errors. I'd appreciate an explanation of why this happens and how to fix my \fieldinfo command (shown below) to use \addvspace.

I tried using \protect\addvspace, but that didn't work either.

Thanks for any help!

\documentclass{book}

\usepackage{tabularx}

% addvspace instead of vspace fails!
\newcommand{\fieldinfo}[2]{\addvspace{\baselineskip}\noindent\begin{tabularx}{\linewidth}{p{0.25in}X}%
        #1  &  #2 \\%
\end{tabularx} \\%
\addvspace{\baselineskip} \\ }%

\begin{document}
A, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi
tristique senectus et netus et malesuada fames ac turpis egestas. Mauris.

\fieldinfo{A}{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
tristique senectus et netus et malesuada fames ac turpis egestas. Mauris.}

\fieldinfo{B}{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
tristique senectus et netus et malesuada fames ac turpis egestas. Mauris.}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum.
\end{document}
share|improve this question

2 Answers 2

up vote 10 down vote accepted

Yor use of \addvspace fails because you are using it without being in vertical mode. Here's the definition of \addvspace:

\def\addvspace#1{%
  \ifvmode
    \if@minipage\else
      \ifdim \lastskip =\z@
        \vskip #1\relax
      \else
      \@tempskipb#1\relax
        \@xaddvskip
      \fi
    \fi
  \else
    \@noitemerr
  \fi}

as you can see, when not in vertical mode, \@noitemrr is called, which produces the error message "Something’s wrong--perhaps a missing \item".

To be able to use \addvspace you need to enter vmode, and this can be done, for example. by using \par:

\documentclass{book}
\usepackage{tabularx}

\newcommand{\fieldinfo}[2]{
  \addvspace{\baselineskip}
  \noindent\begin{tabularx}{\linewidth}{p{0.25in}X}%
        #1  &  #2 \\%
\end{tabularx}%
\par\addvspace{\baselineskip}}%

\begin{document}
A, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi
tristique senectus et netus et malesuada fames ac turpis egestas. Mauris.

\fieldinfo{A}{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
tristique senectus et netus et malesuada fames ac turpis egestas. Mauris.}

\fieldinfo{B}{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
tristique senectus et netus et malesuada fames ac turpis egestas. Mauris.}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum.
\end{document}

Of course, you cannot use \\ just after \addvpace{\baselineskip}

share|improve this answer
    
Thanks Gonzalo. BTW, do you know why \addvspace throws the @noitemerr? It's so confusing. Isn't there a way to offer some useful message to users when writing macros like this? –  srking Apr 1 '11 at 15:59
    
@srking: that's how \addvspace is defined in the LaTeX kernel; you can see the original definition (which I included in my answer) in the Section 16.5 Vertical spacing of the source2e document: tug.org/texlive/Contents/live/texmf-dist/doc/latex/base/… And yes, the error message could have been different and less confusing. –  Gonzalo Medina Apr 1 '11 at 16:12

The confusing error comes because you didn't use \addvspace in vertical mode. Try

\newcommand{\fieldinfo}[2]{\addvspace{\baselineskip}\noindent\begin{tabularx}{\linewidth}{p{0.25in}X}%
        #1  &  #2 \\%
\end{tabularx}\par
\addvspace{\baselineskip}}

That ends the paragraph and then adds the vspace afterward.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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