2

The tabulary package works fine in the setup below when I write out the table header explicitly. But when I wrap the exact same commands inside a custom environment, TeX halts at the \par, with this message:

! File ended while scanning use of \TY@get@body.  

How can I use tabulary inside this environment?

\documentclass{article}
\usepackage{geometry} % need wider textblock for table                                                                                                                                         
\usepackage{parskip}  % everything flushleft with line spaces between paragraphs                                                                                                               
\usepackage{booktabs} % for \toprule                                                                                                                                                           
\usepackage{tabulary}

\newenvironment{schedule}[1]
  {\textsc{#1}\par%                                                                                                                                                                            
    \begin{tabulary}{\textwidth}{llLl}                                                                                                                                                         
    \toprule%                                                                                                                                                                                  
  }
  {\end{tabulary}\par\medskip}

\begin{document}

% Version 1, commands written out, no problem                                                                                                                                                                 
\section*{Herr Dr. Professor}

\textsc{Classes}

\begin{tabulary}{\textwidth}{llLl}
\toprule
Mon., Wed. & 9--10:50 a.m. & Introduction to \TeX, \LaTeX, and friends & Knuth Hall 80\\
Tue. & 12--2:50 p.m. & Seminar: Procrastination through Macros & Lamport Auditorium 95\\
\end{tabulary}

% Version 2, wrapped in environment, will not compile
\section*{Herr Dr. Professor}

\begin{schedule}{Classes}
Mon., Wed. & 9--10:50 a.m. & Introduction to \TeX, \LaTeX, and friends & Knuth Hall 80\\
Tue. & 12--2:50 p.m. & Seminar: Procrastination through Macros & Lamport Auditorium 95\\
\end{schedule}

\end{document}

Version 1 by itself compiles as desired:

enter image description here

  • Use \tabulary and \endtabulary instead of \begin{tabulary} and \end{tabulary} – egreg Jan 13 '16 at 23:21
  • @DavidCarlisle The manual of tabularx, not of tabulary. – egreg Jan 13 '16 at 23:31
  • ... as it says in some manual:-) – David Carlisle Jan 13 '16 at 23:32
2

It's the same problem as in Create environment inside another environment?

The tabularx manual says that in order to use the environment in the definition of another one, you have to use the “internal” forms \tabularx and \endtabularx. The same is true for tabulary although the manual does not specify it.

\newenvironment{schedule}[1]
  {\textsc{#1}\par
    \tabulary{\textwidth}{llLl}
    \toprule
  }
  {\endtabulary\par\medskip}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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