GeneralProblem redefining newline in tabular environment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
daroepi
Posts: 4
Joined: Tue Mar 23, 2010 6:37 pm

Problem redefining newline in tabular environment

Post by daroepi »

Problem redefining newline in tabular environment

I'm new to TeX/LaTeX and I have a problem with the following:

Code: Select all

\documentclass{article}

\def\nl{\tabularnewline & x } %\let\\\nl} % uncomment to work
\def\elem#1{\let\\\nl #1}
\def\mgroup#1#2{#1 & x \elem{#2}}

\begin{document}

\begin{tabular}{l|l}
\mgroup{g1}{one\\two\\three\\four}
\end{tabular}

\end{document}
In the code above, I want to simply let \\ (double backslash) equal my custom newline command \nl which inserts a \tabularnewline and & to jump to the second column of the next row.

The problem is that the \\ substitution stops working after the second row unless I uncomment the comment in the above code. My question is, why do I need to do this?

Another thing, if I incorporate the code in the \elem command directly in \mgroup, it will also fail to work. Why is that?

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply