TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to present something as follows which is mainly under math-mode:

    name1 ::= choice11...   comment11.
            | choice12..    comment12..
            | chocie13.     comment13...

  name2.. ::= choice21...   comment21.
            | choice22..    comment22..
            | choice23.     comment23...

So I want all the labels to be left justified, and all the comments to be left justified. ... ::= ... and | ... are positioned such that = and | are aligned.

Could anyone tell me how to realize this? Thank you very much!

share|improve this question
Do you want = and | to be aligned across both blocks - name1 and name2 and... Also, by 'left adjusted', do you mean \raggedright (flush left) with the text margin? – Werner Aug 9 '11 at 4:05
Sure, across both blocks... by "left adjusted", I mean "left justified"... I have modified the post... – SoftTimur Aug 9 '11 at 4:19
up vote 2 down vote accepted

  &name1&  ::=& 1+1& \textsf{one plus one}\\
  && | & 2\times 2& \textsf{two times two}\\
  && | & 3^3 & \textsf{three raised to the power of three}\\
  &name2&  ::=& choice2 & \textsf{foo}\\
  && | & choice2 & \textsf{bar}\\
  && | & choice3 & \textsf{qux}\\


enter image description here

share|improve this answer

The amsmath package provides the command \intertext{...} which typesets its argument flush left while still preserving subsequent mathematical alignment. From the package documentation:

The command \intertext is used for a short interjection of one or two lines of text in the middle of a multiple-line display structure... Its salient feature is preservation of the alignment, which would not happen if you simply ended the display and then started it up again afterwards. \intertext may only appear right after a \\ or \\* command.

\intertext{...} does not work in an array environment. I'm using the align* environment here (to suppress equation numbering):

\usepackage[showframe]{geometry}% Show page layout frames
\usepackage{calc}% For width calculations


  \intertext{Label 1.}% Text flush left
  X_{\text{long subscript}} ::=&\ 1 &&\text{This is}  \\
    |&\ 2+3 && \text{a comment on the numbers that} \\
    |&\ 4+5\times 6 &&\text{stretch on forever.} \\
\intertext{Label 2..}% Text flush left
  \text{name2..} ::=&\ choice21... && \text{Here are some more comments}  \\
    \also&\ choice22.. && \text{that describe the numbers} \\
    \also&\ \textstyle 1+3+5!+\binom{n}{n-1} && \text{in detail.}

Align* environment from AMSmath with \intertext

Since you are interested in a horizontal alignment across the = and |, I've made a new command \also[<operator>] that you can use to center an optional <operator> (default is |). The first block did not use \also, while the second block does, aligning the two operators. The use of the geometry package is merely to show the horizontal alignment within the text block.

share|improve this answer
In my experience, \intertext works fine in an array environment, and amsmath is just being overcautious in disallowing it. --- Executing the \intertext@ macro will redefine \intertext to just 'do its thing'. I myself patched the array and tabular environments to call \intertext@ locally. But you can also execute it globally. You'll be fine as long as you don't do anything particularly weird with \intertext. – mhelvens Aug 18 '13 at 17:17



\begin{tabular}{@{} p{5mm} R @{\,} L L}
\mc{Label1...}                             \\
  & name1 ::= & choice11...  &comment11.   \\
  &         \V & choice12..   &comment12.. \\
  &         \V & chocie13.    &comment13...\\[10pt]
\mc{Label2...}                             \\
  & name1 ::= & choice21...  &comment21.   \\
  &         \V & choice22..   &comment22.. \\
  &         \V & chocie23.    &comment23...\\


enter image description here

share|improve this answer

Here is a plain-version for good measure:

\def\mymid{\setbox0\hbox{$=$}\mathrel{\hbox to\wd0{\hfil$|$\hfil}}}
    name1   ::&= choice11...       & comment11.  \cr
              &\mymid choice 12..  & comment12.. \cr
              &\mymid choice 13.   & comment13...\cr
    name2.. ::&= choice21...       & comment21.  \cr
              &\mymid choice22..   & comment22.. \cr
              &\mymid choice23.    & comment23...\cr


share|improve this answer

Is this sort of what you are looking for? The second solution uses the newcolumnstypes from the array package to make the tabular definition easier to read.



  &name1   &::=  &\,choice11...  &comment11.\\
  &          &|  &\,choice12..   &comment12..\\
  &          &|  &\,chocie13.    &comment13...\\
  &name2.. &::= &\,choice21...   &comment21.\\
  &          &| &\,choice22..    &comment22..\\
  &          &| &\,choice23.     &comment23...

If it is desired that the label be flushleft, then can use the following

  &name1   &::=  &\,choice11...  &comment11.\\
  &          &|  &\,choice12..   &comment12..\\
  &          &|  &\,chocie13.    &comment13...\\
  &name2.. &::= &\,choice21...   &comment21.\\
  &          &| &\,choice22..    &comment22..\\
  &          &| &\,choice23.     &comment23...
share|improve this answer
I think the OP wants LabelX... to be 'left adjusted', as in flushleft (or \raggedright). – Werner Aug 9 '11 at 4:03
Huh? I made the first column l, won't that do it? – Peter Grill Aug 9 '11 at 4:12
The l will typeset the column on the left _within the array, not flushleft with the text block. – Werner Aug 9 '11 at 4:29
Ok, have updated to use tabular and the array package to allow for custom column definitions. – Peter Grill Aug 9 '11 at 4:36

Your Answer


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.