2

I'm trying to create a new environment based on tabularx. I'd like it to have a \bottomrule at the end. How do I refer to the table rows on the new environment definition? Right now the bottom line is appearing above the rows instead of below them.

\documentclass{article}
\usepackage{array, booktabs, tabularx}

\newcolumntype{L}[1]{>{\hsize=#1\hsize\raggedright\arraybackslash}X}
\newenvironment{funtab}[1]{%
  \tabularx{\textwidth}{@{} L{0.4} L{0.6} L{2.0} @{}}
    \toprule
    Operation&\multicolumn{2}{l}{#1}\\
    \midrule
    %Table body location <------------------------
    \bottomrule
}{%
  \endtabularx
}

\begin{document}

\begin{funtab}{My function name goes here}
  item1 & item2 & item 3 \\
  item1 & item2 & item 3 which is long and should wrap around around around around \\
\end{funtab}

\end{document}
0

1 Answer 1

3

Apparently using \tabularx....\endtabularx 'annoys' \bottomrule, leaving no real tabular environment group, so group the \tabularx... content.

In any case the \bottomrule must be shifted to the \end... part of the tabular environment if it should appear there.

\documentclass{article}
\usepackage{array, booktabs, tabularx}

\newcolumntype{L}[1]{>{\hsize=#1\hsize\raggedright\arraybackslash}X}
\newenvironment{funtab}[1]{%
  \begingroup
  \tabularx{\textwidth}{@{} L{0.4} L{0.6} L{2.0} @{}}
    \toprule
    Operation&\multicolumn{2}{l}{#1}\\
    \midrule
    % Table body location <------------------------
}{%
  \bottomrule
  \endtabularx
  \endgroup
}

\begin{document}

\begin{funtab}{My function name goes here}
  item1 & item2 & item 3 \\
  item1 & item2 & item 3 which is long and should wrap around around around around \\
\end{funtab}

\end{document}
9
  • 2
    What are \begingroup and \endgroup for?
    – egreg
    Sep 18, 2015 at 11:04
  • @egreg: Good question: It just does not work without the outer group
    – user31729
    Sep 18, 2015 at 11:07
  • Really? I just get an overfull because of the indentation box and another because “Operation” doesn't fit, but no other problems, when I remove \begingroup and \endgroup.
    – egreg
    Sep 18, 2015 at 11:10
  • @egreg: I get no bottom rule -- the table is there of course
    – user31729
    Sep 18, 2015 at 11:11
  • 1
    It does work without the group when a \par is added at the end. (This is a strange behaviour of \bottomrule IMHO)
    – cgnieder
    Sep 18, 2015 at 14:45

You must log in to answer this question.

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