[Tex/LaTex] How to split the text into two columns that both have a different width

columnslayouttwo-column

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:

\usepackage{multicol}
\setlength{\columnsep}{1cm}
\setlength{\columnseprule}{1pt}
\def\columnseprulecolor{\color{black}}

\begin{document}

\begin{multicols}{2}
 text..
\end{multicols}

\end{document}

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!

Best Answer

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.

\documentclass{article}
\usepackage[margin=1.5in,showframe]{geometry}
\usepackage{lipsum}

\begin{document}
\lipsum[1-5]\clearpage

\noindent
\begin{minipage}[t]{0.6\textwidth}
\lipsum*[1-2]
\end{minipage}%
\hfill
\vrule
\hfill
\begin{minipage}[t]{0.3\textwidth}
\lipsum*[1]
\end{minipage}

\clearpage
\lipsum[1-5]

\newpage
\end{document}

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

Related Question