Align over many rows in table

The following solution is a refinement of @JohnKormylo's suggestion: change the tabular setup from 2 to 3 columns, and have LaTeX insert = (type mathrel, in math mode) automatically between columns 2 and 3. That way, the spacing around the = symbol will automatically be appropriate for math-mode material.

enter image description here

\documentclass{article}
\usepackage{array,amsmath,multirow}
\newcommand\mc[1]{\multicolumn{2}{c|}{#1}} % handy shortcut macro
\begin{document}

\begin{table}[htbp]
\centering
\begin{tabular}{| c | r @{${}={}$} l |}
\hline
\multicolumn{1}{|l|}{a} & \mc{looooooooooong} \\ \hline
\multirow{3}{*}{cc} & a       & 1    \\ \cline{2-3}            
                       & abbbbbb & 5234 \\ \cline{2-3}            
                       & csf     & 6    \\ \hline
\end{tabular}
\end{table}
\end{document}

How about a solution with only two rows, and an aligned environment? For the horizontal rules inside the aligned environment, I use the capability of \cmidrule to extend on both sides with the (lr) argument. This is obtained with a rather simple code. The 0.95em lengthening of \cmidrule was found by trial and error:

\documentclass{article}
\usepackage{array,amsmath}
\usepackage{booktabs}

\begin{document}

\begin{table}[htbp]
\centering\setlength{\aboverulesep}{0pt}\setlength{\belowrulesep}{0pt}
\begin{tabular}{| c |c|}
\hline
a & looooooooooong\\ \hline
c & $\begin{aligned} a & = 1 \\
\cmidrule(l{-0.95em} r{-0.95em}){1-3}
                       abbbbbb & = 5234 \\
\cmidrule(l{-0.95em} r{-0.95em}){1-3}
                       csf & = 6 \end{aligned}$ \\ \hline
\end{tabular}
\end{table}

\end{document} 

enter image description here


Here are two ways using overlapping of content (since it looks like it should be math, I've used \mathllap and \mathrlap from mathtools), or boxing them into similar-sized boxes (using eqparbox):

enter image description here

\documentclass{article}

\usepackage{mathtools,eqparbox}

\begin{document}

\begin{tabular}{|c|c|}
  \hline
  a & looooooooooong   \\
  \hline
    & $a = 1$          \\
  \cline{2-2}
    & $abbbbbb = 5234$ \\
  \cline{2-2}
  c & $csf = 6$        \\
  \hline
\end{tabular} \qquad
\begin{tabular}{|c|c|}
  \hline
  a & looooooooooong   \\
  \hline
    & $\phantom{abbbbbb}\mathllap{a} = \mathrlap{1}\phantom{5234}$   \\
  \cline{2-2}
    & $abbbbbb = 5234$ \\
  \cline{2-2}
  c & $\phantom{abbbbbb}\mathllap{csf} = \mathrlap{6}\phantom{5234}$ \\
  \hline
\end{tabular} \qquad
\begin{tabular}{|c|c|}
  \hline
  a & looooooooooong   \\
  \hline
    & $\eqmakebox[lhs][r]{$a$} = \eqmakebox[rhs][l]{$1$}$    \\
  \cline{2-2}
    & $\eqmakebox[lhs]{$abbbbbb$} = \eqmakebox[rhs]{$5234$}$ \\
  \cline{2-2}
  c & $\eqmakebox[lhs][r]{$csf$} = \eqmakebox[rhs][l]{$6$}$  \\
  \hline
\end{tabular}

\end{document}

Tags:

Tables

Align