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.

My grammar is long and thin. I'd like to space it out horizontally, as two columns.

\newenvironment{BNF}
  {\captionsetup{type=lstlisting}}
  {}

\begin{BNF}
\caption{My Grammar}
\label{grammar:my-grammar}
\begin{grammar}
<f> ::= "p"
\alt "true"
\alt "false"
\alt <f> <binop> <f>

<binop> ::= "U" (strong until)
 \alt "&&" (logical and)
 \alt $\rightarrow$ (implication)
 \alt $\leftrightarrow$ (equivalence)
\end{grammar}
\end{BNF}

I'd like it to be one Listing, with one caption. But I'd like <f> to be in the first column, and <binop to be in the second. Is this possible?

share|improve this question
    
Can you turn your code fragment into a complete compilable document; it's much easier for people to play with it. –  Alan Munn Jun 28 '13 at 1:51
add comment

1 Answer

up vote 5 down vote accepted

You can do this easily with the multicol package:

\documentclass{article}
\usepackage{listings,caption,syntax}
\newenvironment{BNF}
  {\captionsetup{type=lstlisting}}
  {}
\usepackage{multicol}
\begin{document}

\begin{BNF}
\caption{My Grammar}
\label{grammar:my-grammar}
\begin{multicols}{2}
\begin{grammar}
<f> ::= "p"
\alt "true"
\alt "false"
\alt <f> <binop> <f>
\columnbreak

<binop> ::= "U" (strong until)
 \alt "&&" (logical and)
 \alt $\rightarrow$ (implication)
 \alt $\leftrightarrow$ (equivalence)
\end{grammar}
\end{multicols}
\end{BNF}

\end{document}

output of code

share|improve this answer
add comment

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.