Graphics, Figures & Tablesproblem: tabular with nested environment

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
daroepi
Posts: 4
Joined: Tue Mar 23, 2010 6:37 pm

problem: tabular with nested environment

Post by daroepi »

I have a table with two columns inside which I want to use a custom environment called "mgroup". This environment is defined as follows:

Code: Select all

\newenvironment{mgroup}[1]{#1 &}{\tabularnewline}
An example of how I use it:

Code: Select all

\begin{tabular}{ll}%
\begin{mgroup}{g1}%
one%
\end{mgroup}%
\begin{mgroup}{g2}%
two%
\end{mgroup}%
\end{tabular}
The example does not compile successfully. When I remove the ampersand and tabularnewline it does compile but everything is output on the same row (as expected). The mere use of a nested environment (that uses align and/or newline) seems to cause a problem within tabular.

Can anyone fix the above? Or, can anyone offer another way to accomplish the above? Note, I need to use a nested enviroment of some sort because I may need to process the input arguments in future.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

problem: tabular with nested environment

Post by gmedina »

Hi,

would a command (instead of an environment) be a viable option for you?

Code: Select all

\documentclass{article}

\newcommand\mgroup[2]{#1 & #2\tabularnewline}

\begin{document}

\begin{tabular}{ll}%
\mgroup{g1}{one}
\mgroup{g2}{two}
\end{tabular}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
daroepi
Posts: 4
Joined: Tue Mar 23, 2010 6:37 pm

Re: problem: tabular with nested environment

Post by daroepi »

Thank you kindly for your reply. Though I still hope someone can fix my environments {intellectual itch}, I am grateful to have an alternative solution to my problem.
Post Reply