I am using fancyvrb to list code in a multicols situation. I number the code using:


When the code is in the left column, this is good, but not when it is in the right column. I wish to put the numbers in the right column on the right side.

Is there a way to automatically put the numbers on the side that the code is being listed on? Or is there a way of determining what column I am in in the multicols environment?

  • 2
    In terms of multicol column detection, see Detecting current column in multicol. You should also consider provide a minimal working example (MWE) that illustrates the problem. It helps both the community (to get started on the problem), but also you (in getting an answer your way faster).
    – Werner
    Aug 19, 2013 at 16:03
  • I have followed the advice in "Detecting current column" and have converted to the twocolumn option. Here are several modifications I made: * I created a simple check for column location: <br> \makeatletter \newcommand{\testcol}{\if@firstcolumn left\else right\fi}% \makeatother <br> This can be used as \begin{Verbatim}[frame=single,numbers=\testcol], which resolves to numbers=left correctly. I also modified the \columnbreak and \newpage commands. This way, I can switch back and forth from twocolumn to multicols if necessary. Aug 20, 2013 at 16:26

1 Answer 1


In the current version of multicols on CTAN the feature of finding out in which column you are is not supported. However in Column break only if within first column of multicol I developed code for this and am in the process of finally including it in the official version of multicols. Until this happens you can grap the code posted in that answer make it a package and use it instead of multicols.

You then use

\docolaction{<in the first column>}{<in a middle column>}{<inthe last column>}

and add whatever code you wish into the 3 arguments. What this doesn't offer you is the swap of line numbers if the verbatim text is split over different columns. And to be honest I think providing for this would be difficult.


After a quick look into the fancyvrb documentation I saw a possibility to prevent a Verbatim environment from being broken across columns: there is the key samepage=true that could be used for this.

  • Thanks. That will be a huge help. I have no idea what to do if the Verbatim text goes over columns - I have kept that to a minimum by careful text editing, and in the one case that I could not do that, I put a manual break in and a \columnbreak to force the columns to be correctly recognized. Aug 21, 2013 at 19:17
  • @PaulA.Thompson if your verbatim text is not too long you could at least detect a column change by evaluating the column at the beginning and the end. That way you could generate an alert for manual evaluation. Technically and automatically that could be solved if the verbatim itself would determine for each line in which column it lies which is probably not a weekend project to get efficiently done. Aug 21, 2013 at 20:37
  • Now there is a project for an ambitious grad student. Aug 22, 2013 at 21:21

You must log in to answer this question.

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