Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a table like this:

\begin{tabular}[b]{c}
A \\
B \\
C \\
D \\
\end{tabular}E

The code above places "D" and "E" on the same baseline, no matter what size any of the letters are.

Without changing "E" (I can't make changes to this text), how can I adjust the table, such that "C" and "E" are on the same baseline, no matter what size any of the letters are?

share|improve this question
    
Try \begin{tabular}[c]{c}. –  Yiannis Lazarides Jan 21 '12 at 11:50
    
That centers the content so that "E" is approximately between ""B" and "C". I need the bottom of "C" and the bottom of "E" to be aligned. –  Village Jan 21 '12 at 11:53
add comment

3 Answers

up vote 3 down vote accepted

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}

enter image description here

share|improve this answer
add comment

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}
share|improve this answer
3  
How did you know it is "-6.5 pt"? –  Village Jan 21 '12 at 12:30
    
Why not \raisebox{-6.5pt}{\begin{tabular}...} that would dispense with a mysterious \mbox{} and foreign syntax? –  egreg Jan 21 '12 at 13:28
    
@Vilage It should be half the baseline. Actually it should be 6pt. I edited my post for this. One could incorporate the calculation in the code. –  Yiannis Lazarides Jan 21 '12 at 13:33
    
@egreg originally I had a \leavevmode, which I thought would confuse the OP. I am not too sure if I agree with your statement of foreign syntax. When I started with programming we always learned the primitives and started building abstractions on top of them. A lot of new programmers start from the abstractions and then learn the primitives. The reason I offered this solution, is that a lot of newcomers to (La)TeX don't think in boxes. One needs to think in`boxes` to understand TeX. –  Yiannis Lazarides Jan 21 '12 at 13:43
    
That's why \raisebox does automatically a \leavevmode: where doesn't it lead to "think in boxes"? –  egreg Jan 21 '12 at 13:45
add comment

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}

table with customized alignment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.