我正在尝试使用 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}
我这里做错了什么?当我换成 时tabu
,longtabu
它运行正常。
答案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}