TransWikia.com

How to align contents of table cell to bottom?

TeX - LaTeX Asked on May 1, 2021

I’ve looked at a few answers about aligning the contents of table cells vertically. In the MWE I provide, there are 4 tables within the columns of another table. The tables are of different sizes and I’d like them all aligned along the bottom of their cell.

enter image description here

So the table in the first column should be aligned to the bottom of the outer table.

documentclass{article}
usepackage{tikz}

newcommand{tikzmark}[2][-3pt]{tikz[remember picture, overlay, baseline=-0.5ex]node[#1](#2){};}

tikzset{brace/.style={decorate, decoration={brace}},
 brace mirrored/.style={decorate, decoration={brace,mirror}},
}

newcounter{brace}
setcounter{brace}{0}
newcommand{drawbrace}[3][brace]{%
 refstepcounter{brace}
 tikz[remember picture, overlay]draw[#1] (#2.center)--(#3.center)node[pos=0.5, name=brace-thebrace]{};
}

newcounter{arrow}
setcounter{arrow}{0}
newcommand{drawcurvedarrow}[3][]{%
 refstepcounter{arrow}
 tikz[remember picture, overlay]draw (#2.center)edge[#1]node[coordinate,pos=0.5, name=arrow-thearrow]{}(#3.center);
}

newcommand{annote}[3][]{%
 tikz[remember picture, overlay]node[#1] at (#2) {#3};
}

begin{document}
begin{table}
centering
begin{tabular}{|c|c|c|c|}
hline
 begin{tabular}{ | l |}
    $3 times fact(2)$tikzmark[xshift=0.62em]{d}  hline
    $4 times fact(3)$tikzmark[xshift=0.6em]{f} hline
 end{tabular}
 &  
 begin{tabular}{ | l |}
    $2 times fact(1)$tikzmark[xshift=0.62em]{1}  hline
    $3 times fact(2)$tikzmark[xshift=0.6em]{2}  hline
    $4 times fact(3)$ hline
 end{tabular}
 &  
 begin{tabular}{ | l |}
    $1 times fact(0)$tikzmark[xshift=0.62em]{3}  hline
    $2 times fact(1)$tikzmark[xshift=0.62em]{4}  hline
    $3 times fact(2)$ hline
    $4 times fact(3)$ hline
 end{tabular}
 & 
 begin{tabular}{ | l |}
    $fact(0) = 1$tikzmark[xshift=0.62em]{5}  hline
    $1 times fact(0)$tikzmark[xshift=0.7em]{6}  hline
    $2 times fact(1)$ hline
    $3 times fact(2)$ hline
    $4 times fact(3)$ hline
 end{tabular} hline
end{tabular}
end{table}
drawcurvedarrow[bend right=50,-stealth]{f}{d}
drawcurvedarrow[bend right=50,-stealth]{2}{1}
drawcurvedarrow[bend right=50,-stealth]{4}{3}
drawcurvedarrow[bend right=50,-stealth]{6}{5}

end{document}

One Answer

Just use the [b] option for each tabular. I took the opportunity to put each fact in text mode, for a nicer layout:

documentclass{article}
usepackage{amsmath}
usepackage{tikz}

newcommand{tikzmark}[2][-3pt]{tikz[remember picture, overlay, baseline=-0.5ex]node[#1](#2){};}

tikzset{brace/.style={decorate, decoration={brace}},
 brace mirrored/.style={decorate, decoration={brace,mirror}},
}

newcounter{brace}
setcounter{brace}{0}
newcommand{drawbrace}[3][brace]{%
 refstepcounter{brace}
 tikz[remember picture, overlay]draw[#1] (#2.center)--(#3.center)node[pos=0.5, name=brace-thebrace]{};
}

newcounter{arrow}
setcounter{arrow}{0}
newcommand{drawcurvedarrow}[3][]{%
 refstepcounter{arrow}
 tikz[remember picture, overlay]draw (#2.center)edge[#1]node[coordinate,pos=0.5, name=arrow-thearrow]{}(#3.center);
}

newcommand{annote}[3][]{%
 tikz[remember picture, overlay]node[#1] at (#2) {#3};
}

begin{document}
begin{table}
centering
begin{tabular}{|c|c|c|c|}
hline
 begin{tabular}[b]{ | l |}
    $3 times text{fact}(2)$tikzmark[xshift=0.62em]{d}  hline
    $4 times text{fact}(3)$tikzmark[xshift=0.6em]{f} hline
 end{tabular}
 &
 begin{tabular}[b]{ | l |}
    $2 times text{fact}(1)$tikzmark[xshift=0.62em]{1}  hline
    $3 times text{fact}(2)$tikzmark[xshift=0.6em]{2}  hline
    $4 times text{fact}(3)$ hline
 end{tabular}
 &
 begin{tabular}[b]{ | l |}
    $1 times text{fact}(0)$tikzmark[xshift=0.62em]{3}  hline
    $2 times text{fact}(1)$tikzmark[xshift=0.62em]{4}  hline
    $3 times text{fact}(2)$ hline
    $4 times text{fact}(3)$ hline
 end{tabular}
 &
 begin{tabular}[b]{ | l |}
    $text{fact}(0) = 1$tikzmark[xshift=0.62em]{5}  hline
    $1 times text{fact}(0)$tikzmark[xshift=0.7em]{6}  hline
    $2 times text{fact}(1)$ hline
    $3 times text{fact}(2)$ hline
    $4 times text{fact}(3)$ hline
 end{tabular} hline
end{tabular}
end{table}
drawcurvedarrow[bend right=50,-stealth]{f}{d}
drawcurvedarrow[bend right=50,-stealth]{2}{1}
drawcurvedarrow[bend right=50,-stealth]{4}{3}
drawcurvedarrow[bend right=50,-stealth]{6}{5}

end{document} 

enter image description here

Correct answer by Bernard on May 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP