10

I want to use the multicols environment to display a listing beneath a table:

\begin{multicols}{2}
   \begin{lstlisting}[]
 .....
\end{lstlisting}

\columnbreak

 \begin{table}
       \centering
     \begin{tabular}{r|c|c|c|c|c}
         .....
      \end{tabular}
 \end{table}
\end{multicols}

But this only displays my listing. Am I missing something?

6

Why not a pair of minipage environments?

\begin{center}
\begin{minipage}[t]{.45\textwidth}
\begin{lstlisting}
...
\end{lstlisting}
\end{minipage}\hfil
\begin{minipage}[t]{.45\textwidth}
\begin{tabular}{...}
...
\end{tabular}
\end{minipage}
\end{center}

Play with the width of the minipage's.

| improve this answer | |
18

The multicol package doesn't support normal floats, like table and figure, only page-wide floats, which are starred forms: table* and figure*.

But you do not need the table environment to create the table, that only causes it to float. You could replace the table environment with a center environment, or drop the surrounding environment altogether. If you need a caption, you can use the captionof command from the caption package.

\documentclass{article}
\usepackage{multicol,listings}
\begin{document} 
\begin{multicols}{2}
  \begin{lstlisting}[]
      .....
  \end{lstlisting}
\columnbreak
 \begin{center}
     \begin{tabular}{r|c|c|c|c|c}
         a & b & c & d & e & f 
      \end{tabular}
 \end{center}
\end{multicols}
\end{document}
| improve this answer | |
  • 2
    This should be the accepted answer! – Celdor Oct 8 '17 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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