5

I am producing a document that has "interlinear" qualities. As such, it would be much simpler if I could wrap multiple lines of text at one time. Here is an example of what I want:

Let's take these three sentences as our examples:

1) This is the first line of the document.
2) Here is the document's second line.
3) The third line of the document is here.

Ordinarily, table wrapping might produce something like this for these three lines:

1) This is the first line of the
document.
2) Here is the document's second
line.
3) The third line of the document
is here.

However, I would like all three of the lines to wrap as a group. Here is my desired output:

1) This is the first line of the
2) Here is the document's second
3) The third line of the document
document.
line.
is here.

The three lines are wrapping as a group, not individually.

Is this possible? If so, how?

Ludovic C.
  • 8,888

1 Answers1

1

Here I place such a construct in a \Longunderstack using my macro \thread, which is passed the total number of threads as the first argument, the color as the second argument, and the thread content as the final argument. The width of the thread stack is defined by the \def of \threadwidth. Being a stack, it cannot cross page boundaries.

I had to raise the stack 7pt to align it with the current baseline, which occurs from the borders of the \parbox I think.

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\usepackage{xcolor}
\def\stacktype{L}
\def\stackalignment{l}
\def\threadwidth{2in}
\newcommand\thread[3]{\parbox[t]{\threadwidth}{\baselineskip=#1\baselineskip\color{#2}#3}}
\begin{document}
baseline 
\raisebox{7pt}{\Longunderstack{%
  \thread{3}{red}{This is a test of a red paragraph which wraps every 
    3 lines... if we are lucky}\\
  \thread{3}{blue}{\bfseries And here we have a test in which the second paragraph 
    is a nice dark blue.}\\
  \thread{3}{cyan}{\itshape And finally, we have a test in which the third and 
    last paragraph is cyan.}%
}}
\end{document}

enter image description here

Placing it in a tabular is only complicated by the fact that the value of \baselineskip evaporates inside a tabular and so it must be saved in advance:

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\usepackage{xcolor}
\def\stacktype{L}
\def\stackalignment{l}
\def\threadwidth{2in}
\edef\tmp{\the\baselineskip}
\setstackgap{L}{\tmp}
\newcommand\thread[3]{\parbox[t]{\threadwidth}{\baselineskip=#1\baselineskip\color{#2}#3}}
\begin{document}
\begin{tabular}{|c|l|l|}
\hline
baseline &
\raisebox{7pt}{\Longunderstack{%
  \thread{3}{red}{This is a test of a red paragraph which wraps every 
    3 lines... if we are lucky}\\
  \thread{3}{blue}{\bfseries And here we have a test in which the second paragraph 
    is a nice dark blue.}\\
  \thread{3}{cyan}{\itshape And finally, we have a test in which the third and 
    last paragraph is cyan.}%
}}&
\raisebox{7pt}{\Longunderstack{%
  \thread{2}{orange}{If a macro breaks in the CPU and no one is there to hear it,
    did it indeed break?}\\
  \thread{2}{black}{I think that I shall never see, \LaTeX{} as beautiful as thee}
}}
\tabularnewline
\hline
\end{tabular}
\end{document}

enter image description here