# Text not aligning in table

I asked a previous question on making a table with varying cell size.

Using one of the answers given I was able to create what is seen below. The problem is the text in the lower cells do not align properly and I am not sure how to fix this. Notice that in the top rows all the words are centered while in the bottom rows the words YES and NO in the second column are not (in some cases neither vertically nor horizontally). How can I fix this?

\documentclass{article}
\usepackage{multirow,tabularx}
\usepackage{nccmath}
\usepackage[margin= .75in]{geometry}

\begin{document}
\begin{center}
\abovedisplayskip=-2pt
\belowdisplayskip=-2pt
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{tabularx}{\linewidth}{@{} |c|c|c|>{\fleqn}X<{\endfleqn} @{}}
ORDER & ALL & REPEAT & Formula \\
\hline
\multirow{4}{*}{NO}& \multirow{4}{*}{NO}
& NO    &
$$_{n}C_{r} = \binom{n}{r} = \frac{n!}{(n-r)!r!}$$   \\
\cline{3-4}
&& YES  &
$$_{n-1+r}C_{r} = \binom{n-1+r}{r} = \frac{(n-1+r)!}{(n-1)! \; r!}$$  \\
\hline
\multirow{8}{*}{YES} & \multirow{4}{*}{NO} \multirow{14}{*}{YES}
& NO    &
$$_{n}P_{r} = \frac{n!}{(n-r)!}$$   \\
\cline{3-4}
&& YES  &
$$n^r$$  \\
\cline{2-4}
&& NO &
$$P_{n} = n!$$ \\
\cline{3-4}
&& YES &
$$PR_{n}^{\; n_1,n_2,\dots} = \frac{n!}{n_{1}! \; n_{2}! \dots}$$ \\
\hline
\end{tabularx}
\end{center}
\end{document}


## 2 Answers

Here it is:

\documentclass{article}
\usepackage{multirow,tabularx}
\usepackage{nccmath}
\usepackage[margin= .75in]{geometry}

\begin{document}
\begin{center}
\abovedisplayskip=-2pt
\belowdisplayskip=-2pt
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{tabularx}{\linewidth}{@{} |c|c|c|>{\fleqn}X<{\endfleqn} @{}}
ORDER & ALL & REPEAT & Formula \\
\hline
\multirow{4}{*}{NO}& \multirow{4}{*}{NO}
& NO    &
$$_{n}C_{r} = \binom{n}{r} = \frac{n!}{(n-r)!r!}$$   \\
\cline{3-4}
&& YES  &
$$_{n-1+r}C_{r} = \binom{n-1+r}{r} = \frac{(n-1+r)!}{(n-1)! \; r!}$$  \\
\hline
\multirow{8}{*}{YES} & \multirow{4}{*}{NO}
& NO    &
$$_{n}P_{r} = \frac{n!}{(n-r)!}$$   \\
\cline{3-4}
&& YES  &
$$n^r$$  \\
\cline{2-4}
&\multirow{4}{*}{YES} & NO &  %  <- right placemnent
$$P_{n} = n!$$ \\
\cline{3-4}
&& YES &
$$PR_{n}^{\; n_1,n_2,\dots} = \frac{n!}{n_{1}! \; n_{2}! \dots}$$ \\
\hline
\end{tabularx}
\end{center}
\end{document}


The mistake was the bad placement of the third \multirow{4} statement. The \ multirows commands must be placed in the (row, column) position where the "multicell" starts ((top, left) corner).

• Yes, that fixed the issue. Thank you. – jared May 26 at 19:47

I suggest a better indenting of the code for the table to be easier able to locate special cells. Please see the red numbers in the later following screenshot and the marked lines in the code with <===== 1 etc, as a reference to the red numbers in the screenshot.

The corrected mwe:

\documentclass{article}

\usepackage{multirow,tabularx}
\usepackage{nccmath}
\usepackage[margin= .75in]{geometry}

\begin{document}
\begin{center}
\abovedisplayskip=-2pt
\belowdisplayskip=-2pt
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{tabularx}{\linewidth}{@{} |c|c|c|>{\fleqn}X<{\endfleqn} @{}}
ORDER & ALL & REPEAT & Formula \\
\hline
\multirow{4}{*}{NO} % <=============== 1
& \multirow{4}{*}{NO}  % <========== 2
& NO  % <=========================== 3
& $$_{n}C_{r} = \binom{n}{r} = \frac{n!}{(n-r)!r!}$$   \\
\cline{3-4}
&
& YES   % <========================= 4
& $$_{n-1+r}C_{r} = \binom{n-1+r}{r} = \frac{(n-1+r)!}{(n-1)! \; r!}$$  \\
\hline

\multirow{8}{*}{YES}  % <=============== 5
& \multirow{4}{*}{NOa} % <============ 6
& NO   % <============================ 7
& $$_{n}P_{r} = \frac{n!}{(n-r)!}$$   \\
\cline{3-4}
&
& YES  % <============================ 8
& $$n^r$$  \\
\cline{2-4}
&\multirow{4}{*}{YESa} % <============ 9
& NO
& $$P_{n} = n!$$ \\
\cline{3-4}
&
& YES
& $$PR_{n}^{\; n_1,n_2,\dots} = \frac{n!}{n_{1}! \; n_{2}! \dots}$$ \\
\hline
\end{tabularx}
\end{center}
\end{document}


and the resulting screenshot with red numbers marked:

Please see the correct place for the corrected cell 9. I only added the a tobe able to locate the both cells easier. For your document you can delete them!

• This actually helped a lot. It allowed me to better understand my mistake. Thank you. – jared May 26 at 19:47
• @jared you are welcome! – Mensch May 28 at 7:29