2

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:

enter image description here

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:

enter image description here

  • 2
    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
2

What about the following code?

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}

enter image description here

  • 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
1

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}

enter image description here


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}

enter image description here

  • 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
0

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}

enter image description here

But now, take a closer look:

enter image description here

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

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

  • 1
    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
0

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}

enter image description here

0

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}
\newcommand\mytabstack[1]{{\addstackgap[2pt]{\tabbedLongunderstack[l]{#1}}}}
\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}

enter image description here

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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