# Tabbing and aligning within different table cells

The code

\begin{table}[]
\centering
\begin{tabular}{|l|l|}
\hline
7 Seven  & 7 Seven\\ \hline
6 Six & 6 Six\\ \hline
5 Five & 5 Five\\ \hline
4 Four & 4 Four\\ \hline
3 3c Three-C\\ \phantom{3 }3b Three-B\\ \phantom{3 }3a Three-A & 3 Three\\ \hline
2 2b Two-B\\ \phantom{2 }2a Two-A & 2 Two\\ \hline
1 1b One-B\\ \phantom{1 }1a One-A & 1 One\\ \hline
\end{tabular}
\end{table}


produces the following outpout:

I have looked up several possibilities to align the cells “3 Three”, “2 Two” and “1 One” at the top, but nothing has worked so far. Furthermore, the lines at the right aren’t complete.

Another problem is that the letters “a”, “b” and “c” have a different width. Thus, “Three-C”, “Three-B” and “Three-A” are, for example, not aligned alongside a perfect vertical line. I think tabbing would solve this problem. But is it even possible to use tabbing within a table? And are the linebreaks within a table cell correct? They are marked in red in TeXstudio for Windows:

• Welcome to TeX.SX! You need & also for empty cells. – egreg May 29 '17 at 17:06
• The red highlighting is done, because your editor checks the number of columns your table has (2) but the rows you're ending only have one cell. Just see egreg's comment. – Skillmon May 29 '17 at 17:27

EDIT: Alignment of the right column at the top.

\documentclass[]{scrartcl}

\begin{document}
\begin{tabular}{|l|l|}
\hline
7 Seven  & 7 Seven\\ \hline
6 Six & 6 Six\\ \hline
5 Five & 5 Five\\ \hline
4 Four & 4 Four\\ \hline
\begin{tabular}[t]{@{}l@{}l@{}}
3~ & 3c Three-C\\
& 3b Three-B\\
& 3a Three-A
\end{tabular}&
3 Three\\\hline
\begin{tabular}[t]{@{}l@{}l@{}}
2~ & 2b Two-B\\
& 2a Two-C\\
\end{tabular}&
2 Two\\\hline
\begin{tabular}[t]{@{}l@{}l@{}}
1~ & 1b One-B\\
& 1a One-C\\
\end{tabular}&
1 One\\\hline
\end{tabular}
\end{document}


• How about it...? – Werner May 29 '17 at 17:23
• @Werner brain fart... – Skillmon May 29 '17 at 17:25
• I'm just trying to emphasize that it's odd to answer a question with a question. – Werner May 29 '17 at 17:26
• @Werner the code is a recommendation and as such subject to personal preferences, so I think the question is valid :) – Skillmon May 29 '17 at 17:28

Suggestion: put the numbers in their own columns to have them aligned

\documentclass{article}

\usepackage{multirow}

\begin{document}

\begin{table}
\centering
\begin{tabular}{|lll|l|}
\hline
7 & \multicolumn{2}{l|}{Seven} & 7 Seven\\ \hline
6 &\multicolumn{2}{l|}{Six} & 6 Six\\ \hline
5 &\multicolumn{2}{l|}{Five} & 5 Five\\ \hline
4 &\multicolumn{2}{l|}{Four} & 4 Four\\ \hline
3 & 3c & Three-C & 3 Three\\
& 3b & Three-B & \\
& 3a & Three-A & \\ \hline
2 & 2b & Two-B & 2 Two\\
& 2a & Two-A & \\ \hline
1 & 1b & One-B & 1 One\\
& 1a & One-A & \\ \hline
\end{tabular}
\end{table}

\end{document}


Or following the suggestion of Mico a version with tighter spacing:

\documentclass{article}

\usepackage{multirow}

\begin{document}

\begin{table}
\centering
\begin{tabular}{|l@{\ }l@{\ }l|l|}
\hline
7 & \multicolumn{2}{@{}l|}{Seven} & 7 Seven\\ \hline
6 & \multicolumn{2}{@{}l|}{Six} & 6 Six\\ \hline
5 & \multicolumn{2}{@{}l|}{Five} & 5 Five\\ \hline
4 & \multicolumn{2}{@{}l|}{Four} & 4 Four\\ \hline
3 & 3c & Three-C & 3 Three\\
& 3b & Three-B & \\
& 3a & Three-A & \\ \hline
2 & 2b & Two-B & 2 Two\\
& 2a & Two-A & \\ \hline
1 & 1b & One-B & 1 One\\
& 1a & One-A & \\ \hline
\end{tabular}
\end{table}

\end{document}


• Change \begin{tabular}{|lll|l|} to \begin{tabular}{|l@{\ }l@{\ }l|l|} , and change the four \multicolumn{2}{l|}{...} directives to \multicolumn{2}{@{}l|}{...} to get tighter spacing. – Mico May 30 '17 at 7:19
• @Mico Thanks a lot for your helpful comment! – user36296 May 30 '17 at 8:20

Thanks to you, I have almost almost found the perfect answer.

\begin{tabular}{|l|l|}
\hline
7 Seven  & 7 Seven\\ \hline
6 Six & 6 Six\\ \hline
5 Five & 5 Five\\ \hline
4 Four & 4 Four\\ \hline
\begin{tabular}[t]{@{}l@{}l@{}}
3 3c~ & Three-C\\
\phantom{3 }3b & Three-B\\
\phantom{3 }3a & Three-A
\end{tabular}&
3 Three\\\hline
\begin{tabular}[t]{@{}l@{}l@{}}
2 2b~ & Two-B\\
\phantom{2 }2a~ & Two-A\\
\end{tabular}&
2 Two\\\hline
\begin{tabular}[t]{@{}l@{}l@{}}
1 1b~ & One-B\\
\phantom{1 }1a~ & One-A\\
\end{tabular}&
1 One\\\hline
\end{tabular}


But now, take a closer look:

I know that this is due to the various tabular areas.

samcarter’s solution would avoid this, but the white spaces are huge.

• I've left a comment under @samcarter's answer to show how one might reduce the intercolumn whitespace amounts to "normal" interword whitespace. – Mico May 30 '17 at 7:20

I have found the perfect solution, thanks to your help! I just had to modify your solutions a bit.

\begin{tabular}{|l|l|}
\hline
7 Seven & 7 Seven\\ \hline
6 Six & 6 Six\\ \hline
5 Five & 5 Five\\ \hline
4 Four & 4 Four\\ \hline
\begin{tabular}[t]{@{}l@{}l@{}l@{}}
3~ & 3c~ & Three-C\\
& 3b~ & Three-B\\
& 3a~ & Three-A
\end{tabular}&
3 Three\\\hline
\begin{tabular}[t]{@{}l@{}l@{}l@{}}
2~ & 2b~ & Two-B\\
& 2a~ & Two-C
\end{tabular}&
2 Two\\\hline
\begin{tabular}[t]{@{}l@{}l@{}l@{}}
1~ & 1b~ & One-B\\
& 1a~ & One-C
\end{tabular}&
1 One\\\hline
\end{tabular}


Oh, let's throw a TABstack into the mix... It can accomplish several things at once:

1. It provides a stacked list

2. It can align that list with the top row

3. It can separate into columns the 3a from the Three-C so that proper column alignment is achieved.

The MWE:

\documentclass{article}
\usepackage{tabstackengine}
\setstacktabbedgap{1ex}
\begin{document}
\begin{table}[]
\centering
\begin{tabular}{|l|l|}
\hline
7 Seven  & 7 Seven\\ \hline
6 Six & 6 Six\\ \hline
5 Five & 5 Five\\ \hline
4 Four & 4 Four\\ \hline
3 \mytabstack{3c & Three-C\\ 3b & Three-B\\ 3a & Three-A} & 3 Three\\ \hline
2 \mytabstack{2b & Two-B\\ 2a & Two-A} & 2 Two\\ \hline
1 \mytabstack{1b & One-B\\ 1a & One-A} & 1 One\\ \hline
\end{tabular}
\end{table}
\end{document}


If you want the vertical spacing in the stacked cells to be more like tabular's intrinsic behavior, then redefine

\newcommand\mytabstack[1]{{\tabbedLongunderstack[l]{\strut#1\strut}}}


to achieve