I'm making a report about some code that I've written. I want to split the page into two columns, in such a way that I have code on the left side and (commentary, descriptive, non-code) text on right side.

I do not want to have this layout throughout the whole document.

I would also like to have a vertical line that separates these two columns.

The important part for me is that I want the code column to occupy a lot more space than the text column. The code-columnwidth should be twice as much as the text-columnwith for example.

I have searched the internet for a long time but I couldn't find a suitable solution.

I have tried the following:





But it can't seem to find a way to specify two different columnwidths for each column. What also bothers me is that I cannot indicate precisely what text goes into what column, it just splits it automatically when the bottom of the page is reached, meaning that I sometimes get code on the right column.

Could anyone help me with this problem? I truly am desperate for any kind of solution. Thank you!

  • 1
    Welcome to TeX.SE. Are you familiar with the paracol package?
    – Mico
    Jan 5 '19 at 16:05
  • Take a look at the ‘tcolorbox‘ package Jan 5 '19 at 16:18
  • 1
    Package paracol can take care of that.
    – Bernard
    Jan 5 '19 at 16:24
  • 1
    Would it be possible to mock up an example of what you're looking for? For example, it should show how the two columns interact with one another. Do you have long pieces of text that should push the code (on the left) down? Should the text be centred vertically with respect to the code or at the top of the code line it describes? Do you need word wrapping for the text? What package are you using to write the code?
    – Werner
    Jan 5 '19 at 17:29
  • Thank you all for your efforts! The paracol package has exactly what I was looking for.
    – Chiron
    Jan 5 '19 at 18:23

A simple minipage solution might be more suitable in your case if you don't require page breaks (you didn't mention this as a requirement in your question), otherwise you can have a look at the paracol package mentioned by Mico in the comments.






This way you can put whatever you like in the left column (code, in your case), and the descriptive text on the right.

  • 2
    +1. :-) To assure that the vertical rule is centered between the minipage environments, it's important to write \end{minipage}% rather than just \end{minipage}. The % (comment) symbol serves to suppress the whitespace that otherwise gets inserted (as is visible in the screenshot you posted).
    – Mico
    Jan 5 '19 at 16:27
  • @Mico Thank you for the comment, I'll correct it.
    – Troy
    Jan 5 '19 at 16:28
  • I decided on the paracol package as it is simpler in my opinion and provides exactly everything I was looking for and more (including synchronized columns, etc.) Nevertheless, thank you so much for your efforts!
    – Chiron
    Jan 5 '19 at 18:28

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.