来自新环境的 longtabu

来自新环境的 longtabu

我正在尝试使用 longtabu 环境来替代我之前使用的 tabularx 环境。当我尝试编译此示例时,出现错误:

! LaTeX Error: There's no line here to end.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.26       \end{steplist}

我正在尝试编译的示例:

\documentclass{article}
\usepackage{tabu}
\usepackage{longtable}

\newcounter{StepListCounter}
\newenvironment{steplist} {
    \renewcommand\item[2]{%
        \\[\medskipamount]
        \noindent
        \stepcounter{StepListCounter}
        {\textbf{\arabic{StepListCounter}}} & ##1 & &
        \parbox[c]{1em}{##2} \\
    }

    \setcounter{StepListCounter}{0}
    \longtabu to \linewidth {l X c X}
    %\tabularx{\linewidth}{l X c X}
} {
    \endlongtabu
    %\endtabularx
    \\[\medskipamount]
}

\begin{document}
  \begin{steplist}
  \end{steplist}
\end{document}

我这里做错了什么?当我换成 时tabulongtabu它运行正常。

答案1

tabularx是一种水平模式构造,因此您可以\\在它之后使用,但longtable它是一种垂直模式构造,因此您不能在它之后使用\\

\documentclass{article}
\usepackage{tabu}
\usepackage{longtable}

\newcounter{StepListCounter}
\newenvironment{steplist} {
    \renewcommand\item[2]{%
        \\[\medskipamount]
        \noindent
        \stepcounter{StepListCounter}
        {\textbf{\arabic{StepListCounter}}} & ##1 & &
        \parbox[c]{1em}{##2} \\
    }

    \setcounter{StepListCounter}{0}
    \longtabu to \linewidth {l X c X}
    %\tabularx{\linewidth}{l X c X}
} {
    \endlongtabu
    %\endtabularx
    \medskip
}

\begin{document}
  \begin{steplist}
  \end{steplist}
\end{document}

相关内容