3

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    &   
                \begin{equation}
                    _{n}C_{r} = \binom{n}{r} = \frac{n!}{(n-r)!r!}
                \end{equation}   \\
        \cline{3-4}
            && YES  &   
                \begin{equation}
                    _{n-1+r}C_{r} = \binom{n-1+r}{r} = \frac{(n-1+r)!}{(n-1)! \; r!}
                \end{equation}  \\
        \hline
        \multirow{8}{*}{YES} & \multirow{4}{*}{NO} \multirow{14}{*}{YES}
            & NO    &   
                \begin{equation}
                    _{n}P_{r} = \frac{n!}{(n-r)!}
                \end{equation}   \\
        \cline{3-4}
            && YES  &   
               \begin{equation}
                   n^r
               \end{equation}  \\
        \cline{2-4}
            && NO & 
                \begin{equation}
                    P_{n} = n!
                \end{equation} \\
        \cline{3-4}
            && YES & 
            \begin{equation}
                PR_{n}^{\; n_1,n_2,\dots} = \frac{n!}{n_{1}! \; n_{2}! \dots}
            \end{equation} \\
        \hline
    \end{tabularx}
\end{center}
\end{document}

resulting pdf

1

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    &   
                \begin{equation}
                    _{n}C_{r} = \binom{n}{r} = \frac{n!}{(n-r)!r!}
                \end{equation}   \\
        \cline{3-4}
            && YES  &   
                \begin{equation}
                    _{n-1+r}C_{r} = \binom{n-1+r}{r} = \frac{(n-1+r)!}{(n-1)! \; r!}
                \end{equation}  \\
        \hline
        \multirow{8}{*}{YES} & \multirow{4}{*}{NO}
            & NO    &   
                \begin{equation}
                    _{n}P_{r} = \frac{n!}{(n-r)!}
                \end{equation}   \\
        \cline{3-4}
            && YES  &   
               \begin{equation}
                   n^r
               \end{equation}  \\
        \cline{2-4}
            &\multirow{4}{*}{YES} & NO &  %  <- right placemnent
                \begin{equation}
                    P_{n} = n!
                \end{equation} \\
        \cline{3-4}
            && YES & 
            \begin{equation}
                PR_{n}^{\; n_1,n_2,\dots} = \frac{n!}{n_{1}! \; n_{2}! \dots}
            \end{equation} \\
        \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
1

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
      & \begin{equation}
          _{n}C_{r} = \binom{n}{r} = \frac{n!}{(n-r)!r!}
        \end{equation}   \\
    \cline{3-4}
      &
      & YES   % <========================= 4
      & \begin{equation}
          _{n-1+r}C_{r} = \binom{n-1+r}{r} = \frac{(n-1+r)!}{(n-1)! \; r!}
        \end{equation}  \\
    \hline

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

and the resulting screenshot with red numbers marked:

resulting screenshot

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

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.