[comp.text.tex] TABLES - entries spanning rows

vaisey@fornax.UUCP (Jacques Vaisey) (01/24/91)

I seem to be unable to find out how to make a table in TeX (not LaTeX)
where the entries span rows (spanning columns is easy). For instance, I
want a table of the form:

  -------------------------------------
  |          |         TEST           |
  |   SPAN   |------------------------|
  |          |  TEST2   |  TEST3      |
  -------------------------------------

How do I make "SPAN" come out centred in its box? I imagine that
it is necessary to use \valign, but I can't quite see how.

Does anyone have an example of this sort of table that could be
used as a template?

Thanks,

**> jacques

Jacques Vaisey              |     email -> vaisey@cs.sfu.ca
School of Eng. Science      |     phone -> (604) 291-3818
Simon Fraser Univ.          |       fax -> (604) 291-4951
Burnaby, British Columbia
V5A 1S6 
 

allan@rind.cs.cornell.edu (James Allan) (01/25/91)

vaisey@fornax.UUCP (Jacques Vaisey) writes:
>I seem to be unable to find out how to make a table in TeX (not LaTeX)
>where the entries span rows (spanning columns is easy). For instance, I
>want a table of the form:
>  -------------------------------------
>  |          |         TEST           |
>  |   SPAN   |------------------------|
>  |          |  TEST2   |  TEST3      |
>  -------------------------------------
>Does anyone have an example of this sort of table that could be
>used as a template?


Must admit that I'm not much of an expert here, but the following did
the trick for me:

	\begin{tabular}{|l|@{}l@{}|}
	\hline
	Span & \begin{tabular}{c|c}
		\multicolumn{2}{c}{Test} \\
		\hline
		Test2 & Test3
		\end{tabular} \\
	\hline
	\end{tabular}

The two `@{}' things serve to bring the line under `Test' all the way
to the two vertical lines.  Perhaps someone can provide a nicer or
better solution, but until then....

			-- james allan
			   allan@cs.cornell.edu

allan@rind.cs.cornell.edu (James Allan) (01/25/91)

Oh damn.  Just re-read my note about spanning rows in tables and
noticed that the original poster requested TeX but NOT LaTeX and I
gave a LaTex but NOT TeX response.  Thought I better send out this
patriot missile to deflect a few incoming flames.

Sorry sorry sorry.  Glurg.

ogawa@orion.arc.nasa.gov (Arthur Ogawa) (01/25/91)

LaTeX does not provide for automatically vertical spanning of cells as you
are aspiring. (It is true that horizontal spanning is done via the 
\multicolumn command.) You may get the effect you desire through the 
\cline command and by faking the cell's contents, however:

\begin{tabular}{|c|c|c|}
\hline
\vbox to0pt{\vskip.5\baselineskip\hbox{SPAN}\vss}%
&\multicolumn{2}{c|}{TEST}\\
\cline{2-3}%
&TEST2&TEST3\\
\hline
\end{tabular}

will produce the result you sketched. This method is, however, not very
robust: you must center the SPAN text by hand.

I wrote a table routine for a macropackage built on Plain.tex which does
all this automatically, but you pay a high price for the functionality
in code complexity and in running time.

ogawa@orion.arc.nasa.gov (Arthur Ogawa) (01/25/91)

My apologies, too, for providing LaTeX code instead of TeX. Here's plain
TeX code:

\vbox{%
 \halign{%
  \vrule#&$\vcenter{#}$&\vrule#&$\vcenter{#}$&\vrule#\cr
  \noalign{\hrule}%
  &\hbox{ SPAN \strut}&&
   \halign{%
    \hfil\ # \strut\hfil&\vrule#&\hfil\ # \strut\hfil\cr
    \multispan3 \hfil TEST\strut\hfil\cr
    \noalign{\hrule}%
    TEST2&&TEST3\cr
    }%
   &\cr
  \noalign{\hrule}%
  }%
 }%

Of course, this must be modified to suit the needs of the table you have
in mind, but it will serve as a template.