开发者

Environment inside a longtable with LaTeX

开发者 https://www.devze.com 2023-01-07 17:14 出处:网络
I would like to create a new environment to print a header and a footer between sections of a table. I did this:

I would like to create a new environment to print a header and a footer between sections of a table.

I did this:

\documentclass{article}

\usepackage{longtable}

\newenvironment{env}{Heading&&& \\}{\hline \\}

\begin{document}

\begin{longtable}{p{7cm}lrr}
    \begin{env}
        Content&b&c&d开发者_运维问答
    \end{env}
\end{longtable}

\end{document}

but I get insulted by the compiler. See here for the complete output.

Does someone see the problem?


There are two problems here. First, you need an \\ at the end of the "Content&b&c&d" line. Second, environments don't work inside tabular/longtable — that's where most of your error messages are coming from. It may be possible to diddle them into working, but it's way beyond my TeX-fu. This is the best I can come up with:

\documentclass{article}
\usepackage{longtable}
\newcommand{\startenv}{Heading\tabularnewline}
\newcommand{\stopenv}{\hline\tabularnewline}
\begin{document}

\begin{longtable}{p{7cm}lrr}
\startenv
    Content&b&c&d \\
\stopenv
\end{longtable}

(It is not strictly necessary to use \tabularnewline instead of \\, but it will avoid headaches if you ever mix this with other environments that use \\ for their own purposes.)

0

精彩评论

暂无评论...
验证码 换一张
取 消