# Macro for tabbing with complex line breaks (or similar environment)

I have a complicated transcription with mid-line aligned text. I've been using tabbing to do it automatically, but it obviously doesn't do line breaks.

I want to write a macro (unless something already exist) that could take the following:

1 xxxxxxxxxxxxxxxx\=(tab stop)xxxxxx\=xxxxxxx|xx\=xxxxxxxxxxxx
2                 \>yyyyyyyyyyyyyyyyyyyyyyyyy|yyyyyyyyyyyyyyyyyy
3                                   \>zzzzzzz|zzzzzz
4                                            |  \>aaa


and display it like this:

1 xxxxxxxxxxxxxxxx\=(tab stop)xxxxxx\=xxxxxxx
2                 \>yyyyyyyyyyyyyyyyyyyyyyyyy
3                                   \>zzzzzzz
4 xx\=xxxxxxxxxxxx
5 yyyyyyyyyyyyyyyyyy
6 zzzzzz
7   \>aaa


I want a line break to occur when necessarily and the line to be continued after the last line to be broken and in the same order.

I hope it makes sense and I'm not making it too complicated. I'd appreciate any advice, doing it manually is painful and needs to be redone after any page layout change, i have no experience in LaTeX macros, so pointing me to anywhere I could start would be great.

-
Perhaps a tabular environment could be useful here, but I don't quite understand your intent. Can you give us a more clear idea of the final layout desired? (perhaps uploading (or providing a link) to an image). –  Gonzalo Medina Jun 23 '11 at 21:40
let me ask a simpler question: can I write a macro that would check every line inside the tabbing env and insert a line break if it's too long? –  zbigniew Jun 24 '11 at 9:50

I'm not sure whether you are producing these transcripts in an automated way. Also, whether your example transcript is representative of things in general (for example, you give 2 columns, which I assume to always be the case). I have assumed this in the solution presented below, and made some other assumptions about typesetting (like the font). Here is the basic idea...

We typeset the structure using a tabular that has 2 columns. You supply the tabular content in a form similar to that in your example (specifying the line break with a &), which is then printed twice. The first time, only the left column is shown, while the second time only shows the right column. At each print of the contents, the missing column is gobbled using a technique described in Easiest way to delete a column? The environ package allows to easily collect all the contents in the tabular and makes available (for multiple uses) in \BODY, enabling it to be processed twice.

In the example below I have used \ttfamily (mono-spaced Computer Modern font) to typeset the transcript, since it allows for easy horizontal alignment across lines. Also, I've used \phantom to adjust for padding some lines with the correct number of "blank letters". The array package provides the \newcolumntype macro for specifying the "gobble column" H. The new "line-breakable" tabular is contained with the created transcript environment:

\documentclass{article}
\usepackage{environ}% http://ctan.org/pkg/environ
\usepackage{array}% http://ctan.org/pkg/array
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}% Gobble column

\NewEnviron{transcript}{%
\begin{tabular}{r@{}H}
\BODY
\end{tabular} \par
\begin{tabular}{H@{}l}
\BODY
\end{tabular}
}

\begin{document}

\ttfamily % Monospaced Computer Modern

tabular \textrm{environment:}

\begin{tabular}{r@{}l}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx&xxxxxxxxxxxxxx \\
yyyyyyyyyyyyyyyyyyyyyyyyy&yyyyyyyyyyyyyyyyyy \\
zzzzzzz&zzzzzz \\
&\phantom{aa}aaa
\end{tabular}

transcript \textrm{environment:}

\begin{transcript}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx&xxxxxxxxxxxxxx \\
yyyyyyyyyyyyyyyyyyyyyyyyy&yyyyyyyyyyyyyyyyyy \\
zzzzzzz&zzzzzz \\
&\phantom{aa}aaa
\end{transcript}
\end{document}


The above illustration showcases the regular tabular environment against transcript.

-
Thanks a lot, that's very helpful. Is there also a way to insert the line break (&) automatically when it overflows? –  zbigniew Sep 12 '11 at 16:10
Instead of posting a “Thank you” as an additional answer, you should thank Werner by upvoting his answer (with the upward pointing arrow to the left of it; you need 15 reputation points before you can upvote) and accepting it (by clicking on the checkmark). We want to keep the answer space reserved for actual answers, so this non-answer will be removed from public view soon. –  N.N. Sep 12 '11 at 16:13
sorry, but how can I comment on his answer? there's no link below his answer –  zbigniew Sep 12 '11 at 16:37
You need more reputation to comment on other's posts. –  N.N. Sep 12 '11 at 16:40