🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.text
Article #1207

Re: Nice twocolumn style

#1207
From: Douglas Miller
Date: Thu, 16 Nov 1989 04:09
61 lines
2940 bytes
A few people have asked for more flexible two-column formatting in LaTeX.
These are the macros that I have been using for a while:

% The twocolumns environment can be used anywhere in a one column document to
% produce two column output.  The twocolumns environment may extend for an
% unlimited number of pages, and start and finish mid-page.  Columns are 
% always balanced.  The code works very hard to avoid two-column ``widows''
% and ``orphans''.  No inserts are supported (haven't worked out where to put
% them yet).

\newbox\partialpage
\newbox\leftcolumn
\newdimen\dimen@
\newdimen\colsize
\newdimen\lastpageshrink
\newdimen\dimend
\newenvironment{twocolumns}{\begingroup
   \pagegoal=2\textheight
   \lastpageshrink=\pageshrink
   \output={\global\setbox\partialpage=\vbox{\unvbox255}}\penalty-10000%
   \def\columnout{\trycolumnout}%
   \output={\columnout}%
   \hsize=\textwidth \advance\hsize-\columnsep \divide\hsize by 2
   \columnwidth=\hsize \linewidth=\hsize
   \global\colsize=\textheight
   \global\advance\colsize by-\ht\partialpage
   \vsize=\colsize
   \global\advance\vsize by\lastpageshrink
   \multiply\vsize by2}%
% \end{twocolumns}
   {\pagegoal=4\textheight
   \output={\balancecolumns\pagesofar}\break
   \endgroup \global\vsize=\textheight \pagegoal=\vsize}

\def\pagesofar{\unvbox\partialpage%
   \wd0=\hsize \wd2=\hsize \hbox to\textwidth{\box0\hfil\box2}}
\def\balancecolumns{\setbox0\vbox{\unvbox255} \dimen@=\ht0
   \advance\dimen@ by\topskip \advance\dimen@ by-\baselineskip
   \divide\dimen@ by2 \splittopskip=\topskip
   {\vbadness=10000 \loop \global\setbox3=\copy0
     \global\setbox1=\vsplit3 to\dimen@
     \ifdim\ht3>\dimen@ \global\advance\dimen@ by1pt\repeat}
   \ifdim\dimen@>\textheight \dimen@=\textheight\fi
   \setbox0=\vbox to \dimen@{\unvbox1} \setbox2=\vbox to \dimen@{\unvbox3}
   \if\ht0>\ht2\setbox2=\vbox to\ht0{\unvbox2}\else
   \if\ht2>\ht0\setbox0=\vbox to\ht2{\unvbox0}\fi\fi}

\def\trycolumnout{%
   \global\def\columnout{\leftcolumnout}
   \global\vsize=\colsize
   \unvbox255\penalty\outputpenalty}
\def\leftcolumnout{%
   \global\def\columnout{\rightcolumnout}
   \global\setbox\leftcolumn=\vbox to\vsize{\unvbox255}}
\def\rightcolumnout{%
   \global\def\columnout{\trycolumnout}
   \setbox0=\box\leftcolumn
   \setbox2=\vbox to \vsize{\unvbox255}
   \setbox\@outputbox=\vbox{\pagesofar}\@outputpage
   \global\colsize=\textheight
   \global\vsize=2\colsize}
Technical Details
Message-ID: <2981@csv.viccol.edu.au>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!munnari.oz.au!murtoa.cs.mu.oz.au!viccol!dougcc
References: <702@tuewsd.lso.win.tue.nl> <JBW.89Nov14223155@bucsf.bu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!munnari.oz.au!murtoa.cs.mu.oz.au!viccol!dougcc
From: dougcc@csv.viccol.edu.au (Douglas Miller)
Newsgroups: comp.text
Subject: Re: Nice twocolumn style
Message-ID: <2981@csv.viccol.edu.au>
Date: 16 Nov 89 04:09:11 GMT
References: <702@tuewsd.lso.win.tue.nl> <JBW.89Nov14223155@bucsf.bu.edu>
Organization: Computer Services, Victoria College, Melbourne
Lines: 61