For PlainTeX (I did find similar questions for latex):

  • Q 1: How to ensure upper left cell is two rows tall?
  • Q 2: How to ensure entry in upper left cell is vertically and horizontally centered?

In following image, table on left is as per code below; want guidance on developing code for table on right:

Table on left is as per code below, want guidance on developing code for table on right

Code (for table on left):

% plain TeX with pdftex  


Attempt at adapting example from Seroul and Levy's {\it A Beginner's Book of $TeX$}:  

\item{Q 1}How to ensure upper left cell is two rows tall?  
\item{Q 2}How to ensure entry in upper left cell is vertically and horizontlly centered?  


\catcode`\*=\active \def*{\hphantom{0}}  
\def\vr{\vrule height 12pt depth 5pt} \def\vrq{\vr\quad}  
\+\vr\quad A \quad&\vr\quad Col A\quad&\vr\quad Col B\quad&\cr  
\+\vrq &\vrq Spanning 2 Cols&&\vr\cr  
\+\vrq \# &\vr\hfill Col A\hfill&\vr\hfill Col B\hfill&\vr\cr  
\+\vrq 1 &\vr\hfill R1C1\hfill&\vr\hfill R1C2\hfill&\vr\cr  
\+\vrq 2 &\vr\hfill R2C1\hfill&\vr\hfill R2C2\hfill&\vr\cr  



Used the library and looked at about 10 books on plain TeX -- only one, Malcolm Clark's A Plain TeX Primer address creation of tables which contain not only horizontally combined cells but also vertically combined cells (refer Figures 15.3 and 16.3 of that book).

I tried to modify the table from Section 9.10 of Seroul and Levy's A Beginnner's Book of TeX by using Clark's ideas to add both horizontally and vertically combined cells -- but as can be seen from the figure below, there is the issue of vertical centering, excess vertical space, and vertical "barbs":

illustrates vertical issues:  centering, excess space, and barbs

Here's the code:

% plain TeX with pdftex

     %\def\foovrule{\vrule height 0pt depth 0pt}

     %\def\foohrulefill{\leaders\hrule height 0pt depth 0pt \hfill}

      \def\mr{\omit&height 2pt&&&&&&\cr}
          \vbox to#1\normalbaselineskip
              \noalign{\hrule} \mr
              &&\omit\bf name&&
                     \bf type&&
                     \bf value&\cr
              \mr \noalign{\hrule} \mr
              &&x&& integer&&   1987&     \cr
              \mr \noalign{\hrule} \mr
              &&y&& real&&      3.14159&  \cr
              \mr \noalign{\hrule} \mr
              &&\vspan2{entry needs lowering}&& excess space below&&      excess space below&  \cr
                 \omit\foohrulefill\foovrule  \cr
              &&&&        \multispan3  small vertical barbs from column divider&  \cr
              \mr \noalign{\hrule} \mr
              &&z&& boolean&&   false&    \cr
              \mr \noalign{\hrule}


Attempts to fix the vertical issues (centering, excess space, and barbs) by playing with height and depth of \vrule and \hrulefill (see \foovrule and \foohrulefill) did not help.

Yet Another Update:

Was able to tweak @wipet 's solution to get the following

enter image description here

Here's the tweaks:

1) Removed barbs by making their height 0:

\def\barb{\omit \vrule height 0pt \hfil\vrule}

2) Made spaces above and below entries equal by increasing depth in \halign:

\halign{\vrule height3ex depth2ex

3) Readjusted centering by modifying \def\low#1:


I suspect @wipet can come up with a better way to implement the tweaks; will await for this possibility happening before accepting his solution.

  • 2
    I'd just like to note that I'd consider it better style to not have rules, and to left align everything.
    – morbusg
    Feb 17, 2015 at 9:17

2 Answers 2


I don't understand why your code is such complicated. Here is more simple code which creates exactly the same table as the table mentioned in your question.

   \def\barb{\omit \vrule height 3pt \hfil\vrule}
   \halign{\vrule height3ex depth1ex
           \quad\hfil\it #\unskip\hfil\quad\vrule&% 
           % data:
           \bf name\hfill\ & \bf type & \bf value \crl
           x     & integer & 1987 \crl
           y     & real    & 3.14159 \crl
           \low{entry needs lowering}  & excess space below & exess space below \cr
           \omit &\omit\hrulefill &\omit\hrulefill \cr
           \barb && \cr
                 & \multispan2 \hfil small vertical barbs from column divider \hfil\vrule\cr
           \barb &&\crl
           z     & boolean & false \crl
  • thanks! got what I was looking for after three tweaks to your solution -- have updated my original question with the current approach based on your solution. Is there a way to replace the numbers used (e.g., kern-<number>pt, \halign{\vrule height<number>ex depth<number>ex) by measurements, perhaps of the font being used? Feb 18, 2015 at 2:53
  • @user1823664 ad 1) Simply don't use \barb && \cr(l) in the data area. And replace \hfil\vrule\cr by \hfil\vrule\crl. The re-definition of \barb is another solution, but more curious. Ad 2), 3) the ex unit depends on the font being used. So, only use this unit. For example \def\low#1{\vbox{\hbox{\rm#1}\kern-3ex}}.
    – wipet
    Feb 18, 2015 at 8:50
  • How Seroul and Levy address (2): start with \nointerlineskip and with \strut inside \halign: this will make all rows of uniform height but with no white space above and below -- so add white space above and below entries using \mr of \def\mr{...2pt...} after and/or before each \hrule Feb 18, 2015 at 14:26
  • @user1823664 \mr is not simple solution. More simple is to use bigger strut, i.e. the \vrule height3ex depth2ex in my solution. Then you needn't to write the \mr sequence in data area.
    – wipet
    Feb 18, 2015 at 15:19
  • 1
    @user1823664 If you are studying books about tables in plain TeX, you can compare this with my book math.feld.cvut.cz/pub/olsak/tbn/tbn.pdf pages 129 to 143, section "tables by \halign". Especially very complex table is at the page 142.
    – wipet
    Feb 18, 2015 at 17:58

You could do it using \valign:

\newskip\colskip \colskip=2em
\newtoks\cellformat \cellformat={
  \hsize=\dimexpr\hsize/4 % the width of a cell

\def\cr{\crcr\noalign{\hskip\colskip}} % gets inserted between columns

\valign{& \vfill\the\cellformat #\vfill\tabskip=\baselineskip\crcr
  \span Two rows& 3rd row& 4th row\cr
  1st row 2nd col& 2nd row \& col\cr
  \multispan3\vfil\the\cellformat cell spanning 3 rows\vfil\cr

enter image description here

  • 1
    +1, "People usually work with TeX at least a year before they find their first application for \valign" --- personally I'm still waiting!
    – Thruston
    Feb 7, 2015 at 12:09
  • Thanks; but it looks like \valign makes it hard to get entries that span multiple columns -- have added image to original question to illustrate need for entries that span multiple rows and entries that span multiple columns; also need for vertical and horizontal lines. Feb 7, 2015 at 14:55
  • @user1823664: yes, you can easily span multiple columns with \halign, or multiple rows with \valign, but having both spans in the same table can't be done with the aforementioned primitives (easily, anyway).
    – morbusg
    Feb 7, 2015 at 16:32

You must log in to answer this question.

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