# Misaligned cells using makecell and xtabular

First a minimal example:

\documentclass{article}
\usepackage{makecell}
\usepackage{xtab}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}
\begin{xtabular}{|p{0.65cm}||C{0.7cm}|C{0.7cm}|C{0.7cm}|C{0.7cm}|C{0.7cm}|C{0.7cm}|C{0.7cm}|}
\hline
\texttt{col}& A
& B
& C
& D
& E
& F
& G
\\\hline
\hline
\texttt{1}      &\makecell{0/5\\10/20}
&\makecell{0/5\\---}
&\makecell{---\\10/10}
&\makecell{0/5\\10/20}
&\makecell{---\\10/20}
&\makecell{---\\10/20}
&\makecell{0/5\\0/20}
\\\hline
\texttt{2}      &\makecell{0/10\\5/5}
&\makecell{0/10\\---}
&\makecell{---\\5/5}
&\makecell{0/10\\5/5}
&\makecell{---\\5/5}
&\makecell{---\\5/5}
&\makecell{0/10\\0/5}
\\\hline
\end{xtabular}
\end{document}


Result:

The columns already reach the maximal width.

In the example in the first row B-1 is not like the others, in the second row C-2, E-2 and F-2 are misaligned.

What I want to achieve is that in each row both lines of all cells are on the same height. How can I do that?

• Welcome to TeX.SX! It is the other way around: the other entries are misaligned, because the boxes are too small. – gernot Jan 5 '17 at 17:25
• Good point. You’re right, all cells are "aligned" (=all misaligned) if I force an "overflow" in the other cells, too. !Example The first problem is "solved" causing another problem: Having such a big white space at the bottom does not look good. Can this be solved? Larger columns are not possible. – CFP Jan 5 '17 at 17:36
• What do you mean by larger columns are not possible? What are exactly the constraints? You can reduce the inter-column space by setting \tabcolsep to a smaller value, so that you gain horizontal space, or you can use a smaller font such that the contents of the cells fits into a width of 0.7cm. It is definitely no solution to cause an overflow in all cells and then to reduce the space at the bottom that results from this error. – gernot Jan 5 '17 at 17:41
• There seems also to be extra space at the border of each cell, introduced by \makecell. See the docs of makecell on how to adjust this space. If you tell us what the hard constraints are (like total table width or whatever), we can help you in adjusting the flexible parts. – gernot Jan 5 '17 at 17:51
• The table will later be used in a two-column page document (that’s why I use xtabular) and I will not have enough space to simply enlarge the columns (the column-sizes are already the maximum that is possible). May I should have written that in the first post. I will try your other suggested solutions and see if I can manage it that the content fits into the cells. Also will have a look into the makecell documentation. – CFP Jan 5 '17 at 18:00

As supplement to gernot nice answer, but with preserved vertical lines and simplified writing of cells contents:

\documentclass{article}
\usepackage{array,makecell,multirow}
\usepackage{xtab}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}
{\setcellgapes{4pt}\makegapedcells
\setlength\tabcolsep{3pt}
\begin{xtabular}{|>{\ttfamily}l||*{7}{C{0.9cm}|}}
\hline
col & A & B & C & D & E & F & G \\
\hline
\hline
\multirowcell{2}{1}
&   0/5    10/20
&   0/5    ---
&   ---    10/10
&   0/5    10/20
&   ---    10/20
&   ---    10/20
&   0/5    0/20             \\
\hline
\multirowcell{2}{2}
&   0/10   5/5
&   0/10   ---
&   ---    5/5
&   0/10   5/5
&   ---    5/5
&   ---    5/5
&   0/10   0/5              \\
\hline
\end{xtabular}
}
\end{document}


For a better alignment and spacing:

• Enlarge the width of the columns to 0.9cm. The misalignment is caused by columns that are too narrow, so most entries (except those that you thought are misaligned) are misaligned.

• Save horizontal space by removing the vertical lines

• Make the table better readable by removing the vertical lines

• Improve the spacing and the horizontal lines by using the package booktabs and its horizontal lines.

\documentclass{article}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage{xtab}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}
\begin{xtabular}{p{0.7cm}C{0.9cm}C{0.9cm}C{0.9cm}C{0.9cm}C{0.9cm}C{0.9cm}C{0.9cm}}
\toprule
\texttt{col}& A
& B
& C
& D
& E
& F
& G
\\\midrule
\texttt{1}      &\makecell{0/5\\10/20}
&\makecell{0/5\\---}
&\makecell{---\\10/10}
&\makecell{0/5\\10/20}
&\makecell{---\\10/20}
&\makecell{---\\10/20}
&\makecell{0/5\\0/20}
\\\midrule
\texttt{2}      &\makecell{0/10\\5/5}
&\makecell{0/10\\---}
&\makecell{---\\5/5}
&\makecell{0/10\\5/5}
&\makecell{---\\5/5}
&\makecell{---\\5/5}
&\makecell{0/10\\0/5}
\\\bottomrule
\end{xtabular}
\end{document}