14

The original question is: How to get two columns with different width in LaTeX?

I know this older question: How can I create a two-column layout with different widths (and texts) for the two columns? But that does not really need a two-column layout but only pictures in the margin.

In fact, it is not very difficult to set the column widths separately. I can do it manually in LaTeX, and I can use flowfram package for convinence. But it seems weird at columnbreak. \hsize is not changed until a new paragraph. An example:

\documentclass{article}
\usepackage{microtype}
\usepackage{lipsum}
\usepackage{flowfram}
\onecolumntopinarea{static}{0pt}{.3\textwidth}{\textheight}{0pt}{0pt}
\onecolumntopinarea{static}{0pt}{.6\textwidth}{\textheight}{.4\textwidth}{0pt}
\begin{document}
\lipsum
\end{document}

enter image description here

Then I must do a trial run and add a \par manually at the column break point, and add a \noindent at the beginning of next column. But I think it should be automatic, even in this silly approach.

I know it may be very difficult in LaTeX. I'm not familar with the output route of LaTeX. I only want to know is it possible to do this automatically? Is there any new approach for this?

I know little about ConTeXt. It seems also not easy to use variable column width in ConTeXt. But I noticed a figure in manual of MetaFun:
enter image description here
Thus it seems possible with (or without?) help of MetaPost.

Any information is welcome.

Leo Liu
  • 77,365
  • 3
    Those last examples will use \parshape, which is set on a whole-paragraph basis. TeX doesn't really allow for mid-paragraph changes in a number of parameters. – Joseph Wright Feb 16 '11 at 06:54
  • Thanks. But is it possible to add \par and \noindent automatically at pagebreak in the middle of paragraph, or with help of some script like Lua? – Leo Liu Feb 16 '11 at 07:38
  • possibly a multi-pass approach with some help by the output routine (with or without lua) could be made to do this, but I am not aware of any packages that actually do so. – Taco Hoekwater Mar 09 '11 at 11:14
  • Could this tutorial article by David Salomon from TUGboat be of help in this issue? – morbusg Mar 09 '11 at 13:28

1 Answers1

7

I don't know about using Lua, but I suspect that what you want is not possible with pdfTeX. As Joseph points out, you cannot change a number of parameters in the middle of the paragraph. The \hsize that is in effect at the end of the paragraph is the one that gets used in TeX paragraph builder.

As for column breaks, TeX accumulates vertical material in its "main vertical list" until it has enough to fill a page and then it runs the output routine. (That's a simplification; see The TeXbook or TeX by Topic for full details.) What this means here is that the paragraph has already been broken up into boxes of width \hsize and added to the vertical list (along with some glue between them to keep the baselines \baselineskip apart). So by the time TeX gets around to deciding on the break point for the first column, material that will appear in the final column has already been typeset.

Edit:
In the comments, Hendrik asks about abusing the output routine and unboxing. Even ignoring the difficulty of finding exactly which material needs to be unboxed, I can't think of a good way to deal with hyphens:

\setbox0\vbox{
        \hsize40pt
        \rightskip=5pt
        \parindent=0pt
        hyphen\-ation
}
\setbox0\vbox{
        \unvbox0
        \global\setbox1\lastbox
        \unskip
        \unpenalty
        \setbox2\lastbox
        \global\setbox1\hbox{%
                \unhbox2
                \unskip
                \
                \unhbox1
                \unskip
                \unskip
                \unpenalty
        }
}
\unhbox1
\bye

Here we set box 0 to have known contents.

\vbox(18.94444+0.0)x40.0
.\hbox(6.94444+1.94444)x40.0
..\hbox(0.0+0.0)x0.0
..\tenrm h
..\kern-0.27779
..\tenrm y
..\tenrm p
..\tenrm h
..\tenrm e
..\tenrm n
..\discretionary
..\tenrm -
..\glue(\rightskip) 5.0
.\penalty 400
.\glue(\baselineskip) 3.37697
.\hbox(6.67859+0.0)x40.0, glue set 12.77771fil
..\tenrm a
..\tenrm t
..\tenrm i
..\tenrm o
..\tenrm n
..\penalty 10000
..\glue(\parfillskip) 0.0 plus 1.0fil
..\glue(\rightskip) 5.0

Since we know that it has two lines, we can directly pull it apart and stuff the contents into box 1.

\hbox(6.94444+1.94444)x60.5557
.\hbox(0.0+0.0)x0.0
.\tenrm h
.\kern-0.27779
.\tenrm y
.\tenrm p
.\tenrm h
.\tenrm e
.\tenrm n
.\discretionary
.\tenrm -
.\glue 3.33333 plus 1.66666 minus 1.11111
.\tenrm a
.\tenrm t
.\tenrm i
.\tenrm o
.\tenrm n

Whereas this would have worked had the word not been hyphenated, here we get
"hyphen- ation"

TH.
  • 62,639
  • Thank you, I know that. It might be possible to get this feature through multiple compilation, I hope. – Leo Liu Mar 09 '11 at 10:18
  • 2
    Can't one somehow abuse the output routine to unbox the material again and restart accordingly? I'm not opting to try, but merely commenting on the "suspect that what you want is not possible". – Hendrik Vogt Mar 09 '11 at 10:18
  • @Hendrik: I thought about that. TeX by Topic does say, "it is possible to dissect the page once it is in \box255...inside the output routine." Maybe my statement is incorrect, but since the material in question would be at the top of the page, I'm not sure I can think of a good way to go about this. Maybe invoke the output routine after every paragraph or use \vsplit. – TH. Mar 09 '11 at 11:44
  • @Hendrik: I've edited my answer in attempt to address your comment. If you can think of a way around that, I'd be pretty interested. – TH. Mar 09 '11 at 12:16
  • @TH: Finally I had a closer look at your Edit. What I don't quite understand is why you have \ before \unhbox1 in your code. Without it, you get "hypen-" and "ation", and isn't this what we want? Or am I just a bit slow on the uptake? – Hendrik Vogt Mar 27 '11 at 17:07
  • @Hendrik: Without the \, lines that broke at word boundaries would be smashed together. The example would still give you "hyphen-ation" when what is wanted is "hyphenation". – TH. Mar 27 '11 at 20:52
  • @TH: Yeah, I noticed already yesterday that I was indeed a bit slow on the uptake. Somehow I thought the idea was that the 1st box would go into the 1st column and the 2nd box into the 2nd one. But your point was that it's virtually impossible to take material that is already typeset to a certain line width and typeset it again. Right? Besides hyphenation, inline math is probably also a problem. I guess the problem is similar to the problem in this question. – Hendrik Vogt Mar 28 '11 at 15:22