2

I'm trying to generate a table, but I don't understand why the inequality in the third line does not appear correctly.

Could you please help me fix this error? Thank you so much!

%
\documentclass[12pt]{extreport}
\usepackage[left = 1in, right = 1in, top = 0.7in, bottom = 0.7in]{dsfont,bbm,geometry,amsmath}
\usepackage{tikz,lipsum,lmodern,amssymb,parskip,hyperref,multirow}

\begin{document}

$$\begin{center}
\begin{tabular}{ |l|c|c| }
\hline
\multirow{3}{*}{W(x,y)}
 & & \\
 & $ y \ge \dfrac{1}{2} $ & $ y < \dfrac{1}{2} $ \\
  & & \\ \hline
\multirow{3}{*}{x \ge \dfrac{1}{2} }
 & & \\
 & $ \binom{n}{r} $ & $ \left(\!\!{n\choose r}\!\!\right) = \binom{n+r-1}{r} $ \\
  & & \\ \hline
\multirow{3}{*}{x < \dfrac{1}{2}}
 & & \\
 & $ P(n,r) $ & $ n^r $ \\
  & & \\ \hline
\end{tabular}
\end{center}$$


\end{document}

enter image description here

Akira
  • 1,215

2 Answers2

2

For your table you do not need multirow cells. Also array is more suitable than tabular. Using the makecell package, you may add vertical gaps above and below cells’ contents:

\documentclass[12pt]{extreport}
\usepackage[hmargin=1in, vmargin=0.7in]{geometry}
\usepackage{bbm, lmodern}
\usepackage{amsmath,amssymb}
\usepackage{makecell, multirow}

\begin{document}

\[
    \setcellgapes{3pt}
    \makegapedcells
\begin{array}{ |>{\displaystyle}l|*{2}{>{\displaystyle}c|} }
    \hline
W(x,y)             & y \ge \frac{1}{2}     & y < \frac{1}{2}  \\
    \hline
x \ge \frac{1}{2}  & \binom{n}{r}          & \binom{n}{r}=\binom{n+r-1}{r}   \\
    \hline
x < \frac{1}{2}    & P(n,r)                & n^r               \\
    \hline
\end{array}
\]
\end{document}

enter image description here

Sveinung
  • 20,355
Zarko
  • 296,517
  • If you like to have more vertical space above/below cells' contents, just increase cell gapes from 3pt to for example 9pt, i.e. use \setcellgapes{9pt}. – Zarko Dec 06 '19 at 10:49
  • @Sveinung, thank you very much for improving explanation. – Zarko Dec 06 '19 at 10:50
1

You have to use math mode in all cells. However, \multirow is not necessary. Here I make two proposals:

\documentclass[12pt]{report}
\usepackage[
  left = 1in,
  right = 1in,
  top = 0.7in,
  bottom = 0.7in
]{geometry}

\usepackage{array}

\usepackage{amsmath}
\usepackage{lmodern}
\usepackage{fixcmex} % important with lmodern
\usepackage{booktabs} % for the second table

\newcommand{\bbinom}[2]{\left(\!\!\binom{#1}{#2}\!\!\right)}
%\newcommand{\addbigstrut}{\vphantom{\Bigg|}}
\newcommand{\addbigstrut}{\vphantom{\left|\rule{0pt}{1cm}\right|}}

\begin{document}

\begin{equation*}
\newcolumntype{?}[1]{>{\displaystyle\addbigstrut}#1}
\begin{array}{ | ?{c} | ?{c} | ?{c} | }
\hline
W(x,y) & y \ge \dfrac{1}{2} & y < \dfrac{1}{2} \\
\hline
x \ge \dfrac{1}{2} & \binom{n}{r} & \bbinom{n}{r} = \binom{n+r-1}{r} \\
\hline
x < \dfrac{1}{2} & P(n,r) & n^r \\
\hline
\end{array}
\end{equation*}

\bigskip

\begin{equation*}
\newcolumntype{?}[1]{>{\displaystyle}#1}
\begin{array}{?{l}?{c}?{c}}
\multicolumn{3}{c}{W(x,y)} \\
\midrule
\addlinespace
& y \ge \dfrac{1}{2} & y < \dfrac{1}{2} \\
\addlinespace
\cmidrule(r){2-2}\cmidrule(l){3-3}
\addlinespace
x \ge \dfrac{1}{2} & \binom{n}{r} & \bbinom{n}{r} = \binom{n+r-1}{r} \\
\addlinespace
x < \dfrac{1}{2} & P(n,r) & n^r
\end{array}
\end{equation*}

\end{document}

enter image description here

Note also the definition for the binomial coefficient with double parentheses.

egreg
  • 1,121,712