Vertically align the cell of a table with the baseline of surrounding text
A much simpler solution, using TeX commands. Remember that for TeX everything are boxes.
\documentclass{article}
\begin{document}
\mbox{}\raise-6.0pt\hbox{
\begin{tabular}[c]{c}
A \\
B \\
C \\
D \\
\end{tabular}}E
\end{document}
Assuming no \hline
and that the table cells have "normal" size, this should work (the setting of \arraystretch
is just to show that it can be done):
\documentclass{article}
\newsavebox{\lowertabularbox}
\newenvironment{lowertabular}[1][0]
{\newcommand{\lowertabulararg}{#1}\begin{lrbox}{\lowertabularbox}
\begin{tabular}[b]}
{\end{tabular}\end{lrbox}%
\raisebox{-\dimexpr\arraystretch\baselineskip*\lowertabulararg\relax}{\usebox{\lowertabularbox}}}
\begin{document}
\renewcommand{\arraystretch}{1.4}
\begin{lowertabular}[0]{c}
A \\
B \\
C \\
D \\
\end{lowertabular}E
\begin{lowertabular}[1]{c}
A \\
B \\
C \\
D \\
\end{lowertabular}E
\begin{lowertabular}[2]{c}
A \\
B \\
C \\
D \\
\end{lowertabular}E
\begin{lowertabular}[3]{c}
A \\
B \\
C \\
D \\
\end{lowertabular}E
some text below to ensure that all is going well
\end{document}
Here's a solution using TikZ nodes for positioning on baselines. In the example, we align at the third row.
\documentclass{article}
\usepackage{tikz}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
baseline=(#1.base)] \node (#1) {#2};}
\begin{document}
\tikz[overlay,remember picture,baseline=(cell.base)]{
\node (table) {\begin{tabular}{c}
A \\
B \\
\tikzmark{cell}{C} \\
D \\
\end{tabular}};}
\quad text aligned with the third row
\end{document}
The macro \tikzmark
produces a node we called cell
. The whole table has been put into a node contained in a TikZ environment, and we defined that the baseline of this environment (with the table) should be the base of this node. This way the table gets the desired baseline, matching the baseline of the following text.
Once having such TikZ nodes, it gives you further possibilities, such as drawing arrows or braces or using it for further alignment. Have a look at Highlighting elements in a matrix to see what I mean.