[comp.text.tex] Vertical centering in tables - Summary

estes@iris.ucdavis.edu (Robert Estes) (08/21/90)

There appeared to be enough interest, so I am posting a summary of the
responses I obtained.  Method #1 below, although a little long, seems to
work the best.  It works better than Method #2 because the tabular
environment adds a little horizontal space on either side of the
headings, therefore, using it in both columns gives more consistent
spacing.  Methods #3 and #4 need more vertical space at the top and
bottom, which might be accomplished with struts, or something (I
didn't try, sorry).

Thanks to all for the help.

Robert

Method #1: from mitano@top.cis.syr.edu

\documentstyle{article}
\begin{document}
\begin{tabular}{|c|c|} \hline
\begin{tabular}{c} Column \\ \#1 \end{tabular} & 
\begin{tabular}{c} Column \#2 \end{tabular} \\ \hline
1985 & 43.2 \\ \hline
1992 & 51.6 \\ \hline
\end{tabular}
\end{document}

Method #2: a minor modification

\documentstyle{article}
\begin{document}
\begin{tabular}{|c|c|} \hline
\begin{tabular}{c} Column \\ \#1 \end{tabular} & Column \#2 \\ \hline
1985 & 43.2 \\ \hline
1992 & 51.6 \\ \hline
\end{tabular}
\end{document}

Method #3: from Edgar Holman and Fred Douglas

\documentstyle{article}
\begin{document}
\begin{tabular}{|c|c|} \hline
\parbox{4em}{\centering Column \\ \#1} & Column \#2 \\ \hline
1985 & 43.2 \\ \hline
1992 & 51.6 \\ \hline
\end{tabular}
\end{document}

Method #4: from unify!uunet!microsoft!t-rayc@csusac.ecs.csus.edu

\documentstyle{article}
\begin{document}
\begin{tabular}{|c|c|} \hline
\hbox{$\vcenter{\halign{\hfil#\hfil\cr Column\cr\#1\cr}}$} & Column \#2 \\ \hline
1985 & 43.2 \\ \hline
1992 & 51.6 \\ \hline
\end{tabular}
\end{document}

zhou@linac.fnal.gov (Ping Zhou) (08/22/90)

  Method #2: a minor modification

  \documentstyle{article}
  \begin{document}
  \begin{tabular}{|c|c|} \hline
  \begin{tabular}{c} Column \\ \#1 \end{tabular} & Column \#2 \\ \hline
  1985 & 43.2 \\ \hline
  1992 & 51.6 \\ \hline
  \end{tabular}
  \end{document}

How about using \begin{tabular}{@{}c@{}} instead of \begin{tabular}{c} in
the nested tabular environment ? The spacing should have been taken care of
in the parent tabular environment. Adding extra space is not appropriate.
Second thought, do we really care ?

kilis@cs.umn.edu (Danny Kilis) (08/22/90)

In article <7592@ucdavis.ucdavis.edu> estes@iris.ucdavis.edu (Robert Estes) writes:
>
>Method #1: from mitano@top.cis.syr.edu
>
>\documentstyle{article}
>\begin{document}
>\begin{tabular}{|c|c|} \hline
>\begin{tabular}{c} Column \\ \#1 \end{tabular} & 
>\begin{tabular}{c} Column \#2 \end{tabular} \\ \hline
>1985 & 43.2 \\ \hline
>1992 & 51.6 \\ \hline
>\end{tabular}
>\end{document}
>
>Method #2: a minor modification
>
>\documentstyle{article}
>\begin{document}
>\begin{tabular}{|c|c|} \hline
>\begin{tabular}{c} Column \\ \#1 \end{tabular} & Column \#2 \\ \hline
>1985 & 43.2 \\ \hline
>1992 & 51.6 \\ \hline
>\end{tabular}
>\end{document}

There would seem to be a problem if one needs to insert a line between
Column and \#1, i.e.,

\begin{tabular}{c} Column \\ \hline \#1 \end{tabular} & Column \#2 \\ \hline

The line would not go across the entire box!  Any suggestion?





				Danny Kilis

				INTERNET: kilis@umn-cs.cs.umn.edu
				CSNET:   kilis@umn-cs.CSNET
				USENET:  ....!umn-cs!kilis
				BITNET:  danny@umnhcs