I prefer to use \begin{multicols}{2}
over \documentclass[12pt,twocolumn]{article}
so I can control when to have 2 columns and when not.
The problem comes when using \begin{Verbatim}....\end{Verbatim}
.
With \documentclass[12pt,twocolumn]{article}
verbatim automatically wraps inside each column and will not overflow to the other column. But when using \begin{multicols}{2}
it does not do this, and it will overflow to the column next to it.
MWE:
\documentclass[12pt]{article}
\usepackage{multicol}
\setlength{\columnsep}{20pt}
\setlength{\columnseprule}{0.01pt}
\usepackage{fancyvrb}
\begin{document}
\begin{multicols}{2}
\begin{Verbatim}
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
\end{Verbatim}
\end{multicols}
\end{document}
MWE for twocolumn
\documentclass[12pt,twocolumn]{article}
\setlength{\columnsep}{20pt}
\setlength{\columnseprule}{0.01pt}
\usepackage{fancyvrb}
\begin{document}
\begin{Verbatim}
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
\end{Verbatim}
\end{document}
side-by-side
The solution I came up with is to put Verbatim
in minipage, using columnwidth
as size for width of minipage, and that worked to some extent, but for some reason, I can't make the width of the minipage smaller than column width, as verbatim still goes a little over.
When I write say 0.6\columnwidth
it has no effect on the result. It looks the same for any value I tried.
\documentclass[12pt]{article}
\usepackage{multicol}
\setlength{\columnsep}{20pt}
\setlength{\columnseprule}{0.01pt}
\usepackage{fancyvrb}
\begin{document}
\begin{multicols}{2}
\begin{minipage}{0.6\columnwidth}
\begin{Verbatim}
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
blablabla blablabla blablabla blablabla
\end{Verbatim}
\end{minipage}
\end{multicols}
\end{document}
question is: What is the best way to handle Verbatim
in multicols environment?
\setlength{\textwidth}{469pt}
to themulticol
version and you'll see that the output is the same (except for the balancing of columns).Verbatim
(likethe standard
verbatim`) does not wrap lines, the line breaks are as in the original source, so it is up to you to use a suitable font size. The behaviour seems no different in twocolumn or multicol