5

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?

1
  • Can you turn your code fragment into a complete compilable document; it's much easier for people to play with it.
    – Alan Munn
    Commented Jun 28, 2013 at 1:51

1 Answer 1

5

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .