8

Forgive me for asking what is probably a trivial question. I'm working through the books but always seem to be confused when I sit down at the computer.

  • I'm using plain TeX.
  • I have three multiple-paragraph chunks-of-text.
  • I want to line them up together so they spread horizontally across the page.

In other words, I want to do this:

This is a               This is another                 Hey look! A third
sentence.               nice sentence.                  sentence or two

                        Whoa, another paragraph!

It seems to me I want three vboxes with \hfill between them. I am not comprehending what additional steps I'm missing.

I assume that a solution would generalize to more boxes and not be dependent on the tabular formatting mechanism. I think this is probably a very simple problem I have greatly overthought.

3 Answers 3

9

You want to set the \hsize of your vertical boxes, and as you want to align the baseline of the first line in the vertical boxes you want \vtop. Probably you need to give TeX some 'room to manoeuvre' in terms of the narrow boxes, so I'd use \sloppy or similar (from LaTeX). You also probably want no \parindent but do seem to want a \parskip. That leads to something like

\long\def\parbox#1{%
  \leavevmode
  \vtop{%
    \hsize0.2\hsize % Pick your size here
    \parindent0pt %
    \parskip\baselineskip
    \sloppy
    #1\par
  }%
}
\def\sloppy{%
  \tolerance 9999 %
  \emergencystretch 3em %
  \hfuzz 0.5pt %
  \vfuzz \hfuzz
}
\noindent
\parbox{This is a sentence}\hfil
\parbox{This is another nice sentence.\par  Whoa, another paragraph!}\hfil
\parbox{ Hey look! A third sentence or two}
\bye

One could of course set things up to have a 'spread these evenly' mechanism for an arbitrary number of boxes if you wanted, but that looks like more work than it's worth (particularly for a plain TeX context where the mark-up usually hides very little). I've hard-coded the width here, but in a real case I guess you'd perhaps make that a second argument.

2
  • Imho "sloppy" should be renamed to "abomination"
    – morbusg
    Jun 10, 2015 at 11:29
  • 1
    @morbusg There are various approaches here (I note egreg's used \raggedright): you do have to have some give somewhere for a narrow column. I've just picked one I could easily copy-paste :-)
    – Joseph Wright
    Jun 10, 2015 at 11:36
9

You may want to use \halign:

\long\def\vtopragged#1#2{\vtop{\hsize=#1 \raggedright #2}}

\begingroup
\parindent=0pt
\tabskip=0pt
\halign to\hsize{%
  \vtopragged{.2\hsize}{#}\tabskip=0pt plus 1fill &
  \vtopragged{.2\hsize}{\parskip=\baselineskip #}\tabskip=0pt plus 1fill &
  \vtopragged{.2\hsize}{#}\tabskip=0pt \cr
  This is a sentence.&
  This is another nice sentence.

  Whoa, another paragraph!&
  Hey, look! A third sentence or two.

  This one without a blank line between paragraphs.\cr
}
\endgroup
\bye

enter image description here

2

You may also want to use \valign:

\valign{%
    \vtop{%
    \hsize50mm
    \raggedright\parindent0pt\tolerance9999
    #
    }
\cr
    This is a sentence.\cr
    This is another\hfil\break nice sentence.\hfil\break

    Whoa, another paragraph!\cr
    Hey, look! A third\hfil\break sentence or two.\cr
}
\bye

You must log in to answer this question.

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