2

Avoiding the usage of the multicols package, what would be the proper way of having a piece of text in a page (doesn't matter if it is a new page, although it would be desired if it is halfway a two-columns page) that spans two columns and a code right there that also spans them?

MWE:

The following MWE shows what I've tried, but an error arises when uncommenting the lstlisting environment (ergo the question title).

\documentclass[journal,twoside]{IEEEtran}
\usepackage{listings}

\begin{document}
This is an empty example page.
\twocolumn[
  \begin{@twocolumnfalse}  
This part of the document must span the two columns when it is too large.
%\begin{lstlisting}
%A code listing is needed here.
%\end{lstlisting}
  \end{@twocolumnfalse}
]
This part of the document doesn't span the two columns when it is too large.
\end{document}

Just to let people looking for the error find this page I'll cite the appearing error:

Argument of \lst@next has an extra }.
<inserted text> 
                \par 
l.13 ]

Additional Questions (if allowed):

The main idea is to meet the initial request, however, if your kindness go beyond sight, you may want to answer to me:

  • Why the conflict happens?
  • How should one solve it?
Hans
  • 1,013
  • This answer might give some insight as to why: https://tex.stackexchange.com/a/30006/117534. – Troy Nov 26 '17 at 08:35
  • Your example code (without the lstlisting environment) places the full-width material at the top of a new page. Have you considered using a table* (or figure*) environment, without a \caption diective, to typeset the material? It works just fine with the lstlisting material, by the way. And, as a bonus, you automatically get some whitespace inserted between the full-width and two-column material. – Mico Nov 26 '17 at 08:42

1 Answers1

4

@Troy's comment provides a good reference for why you're experiencing the problem, using the approach you've outlined in your posting.

I interpret your typographic objective (as opposed to the way you've tried to implement the objective) as follows: typeset some material, which includes a lstlisting environment, in single-column mode at the start, i.e., top of a page. If that's the case, you could employ a table* environment. Note that this approach automatically provides for some whitespace being inserted between the single-column and two-column parts of the page.

enter image description here

\documentclass[journal,twoside]{IEEEtran}
\usepackage{listings,lipsum}
\newcommand{\blurb}{This part of the document must span both columns when it is too large.\ }

\begin{document}
This starts off a non-empty page

\begin{table*} % this will be placed at the top of the *next* page
\blurb\blurb\blurb

\begin{lstlisting}
A code listing is needed here.
A code listing is needed here.
\end{lstlisting}

\blurb\blurb\blurb
\end{table*} % note that we don't provide a "\caption" statement.

\lipsum[1-20] % filler text for pages 1 and 2
\end{document}
Mico
  • 506,678
  • "This starts off a non-empty page", led me to realize exactly that, what I meant is something like "Intentionally blank". Thanks I like your approach. – Hans Nov 27 '17 at 05:09