Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In my case I need to break a multi-line object, as in a matrix, aligned equations, or table, and enter them one row/line at a time. There will be plain text between such rows. There should be NO carriage/line return (no \cr, \\). The original alignment is to be preserved (or something close to it) so that if the interspersed text lines were not there the object would look as it is normally typeset.

An example: Suppose M is a 3 by 3 matrix I want to be broken to three individual rows so that

Row 1

a lengthy text segment

Row 2

a lengthy text segment

Row 3

will come out with Rows 1,2,3 aligned as they normally would in the original matrix.

To restate 1: Can I "pre-type set" a matrix M (which has just entries on a line and no connected elements such as matrix delimiters, parentheses, etc, across lines) and then do "a verbatim copy-paste" of the individual rows of the output where I need them?

To restate 2: Should I use some sort of home-made tabbing template? Just space certain elements by a certain distance. Any suggestions?

To restate 3: How would I a make the scrolling text program in How to simulate terminal output accept a multi-line aligned structure such as a matrix?

share|improve this question
1  
Please add an illustration of the output that you want to achieve. –  Ian Thompson Feb 5 '12 at 15:32
1  
The additional text is still insufficient to understand fully your need. For example, what to do with the matrix delimiters? –  egreg Feb 5 '12 at 16:57
    
Would you maybe be served by using the fleqn documentclass option? It will have all displayed math items be flush-left aligned. –  Mico Feb 5 '12 at 17:22
1  
Instead of explaining, it would be best to show what you mean via a fully compilable MWE that illustrates the problem. Then the solution is more likely to work for your specific case. –  Peter Grill Feb 5 '12 at 18:42
    
@IanThompson Please see edited question "To restate 3" –  Maesumi Feb 8 '12 at 1:48

2 Answers 2

up vote 3 down vote accepted

As others have commented it is difficult to know exactly what you want. Perhaps a simpler method will suffice, but for fine alignment control I often use \phantom along with \makebox.

Here is a short example to illustrate. Note that to better illustrate the alignment the following was done within a single align, but the MWE below show how the same techniques can be used across other elements. Note that:

  • In the first three equations, each term is aligned with the corresponding one above.
  • In the fourth equation, \arcsin(x) is centered exactly between \sin(x) + h(x).

enter image description here

Explanation:

The \phantom{} will take up as much space (both horizontal and vertical) as the parameter given to it. There is also a \vphantom{} which will take up only vertical space (zero horizontal width), and \hphantom{} which take up only horizontal space (and zero height).

So, for the second equation we have:

\phantom{f(x) +{}} g(x)  &= \phantom{\cos(x) +{}}          {\sin(x)} \phantom{{}+ h(x)}

The first \phantom{f(x) +{}} takes up as much space as would be taken up by f(x) +{}. The trailing {} are necessary so that the + is treated as a binary operator. This also applies to the other two \phantoms on this line. Also note that the {\sin(x)} was necessary to eliminate the additional space that would have been inserted to the left of \sin(x). The necessary space was already inserted with the \phantom via the {}, so we don't want this inserted twice.

The case of the third equation is very similar to the second.

In the fourth equation I illustrate how to place text relative to some other text. Here I use a \makebox[<width>][c]{<text>} which will place the given <text> in the space taken up by the specified <width>. The second parameter is used to control the alignment of the placed <text>. In this case I used [c] to center, but this could also be [r] for right aligned, or [l] for left aligned.

\newcommand*{\PhantomText}[1]{\makebox[\widthof{$\sin(x) + h(x)$}][c]{$#1$}}%

To compute the precise width I use \widthof{} from the calc package. So, with the above definition of \PhantomText{\arcsin(x)}

Code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{calc}

\newcommand*{\LongText}{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet}% For dummy text

\newcommand*{\PhantomText}[1]{\makebox[\widthof{$\sin(x) + h(x)$}][c]{$#1$}}%

\begin{document}
\begin{align*}
             f(x) +    g(x)  &=          \cos(x) +              \sin(x)             + h(x) \\
    \phantom{f(x) +{}} g(x)  &= \phantom{\cos(x) +{}}          {\sin(x)} \phantom{{}+ h(x)}\\
    f(x)  \phantom{{}+ g(x)} &=          \cos(x) \phantom{{} +  \sin(x)}            + h(x) \\
    s(x)  \phantom{{}+ g(x)} &= \phantom{\cos(x) +{}} \PhantomText{\arcsin(x)}
\end{align*}
%
The following is just to illustrate how to use this with separate `align` envionments.
\begin{align*}
    f(x) + g(x) &= \cos(x) + \sin(x) + h(x)
\end{align*}
\LongText
\begin{align*}
    \phantom{f(x) +{}} g(x)  &= \phantom{\cos(x) +{}}          {\sin(x)} \phantom{{}+ h(x)}
\end{align*}
\LongText
\begin{align*}
    f(x) \phantom{{}+g(x)}  &= \cos(x) \phantom{{} + \sin(x)} + h(x)
\end{align*}
%
\begin{align*}
    s(x) \phantom{{}+ g(x)} &= \phantom{\cos(x) +{}} \PhantomText{\arcsin(x)}
\end{align*}
\end{document}
share|improve this answer

It depends on the context, perhaps you are just looking for \multicolumn{3}{p{\linewidth}{....} which works in standard tabular/array. The AMS alignments (mostly) support an \intertext command for inserting non-aligned text between rows.

share|improve this answer
    
Or \shortintertext from the mathtools package which yields shorter vertical spacing. –  Peter Grill Feb 5 '12 at 19:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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