1

Here is a minimal working example of my table :

\documentclass[10pt,a4paper]{article}
\usepackage{color}
\usepackage{amsmath}
\usepackage{colortbl}
\usepackage{array}

\definecolor{myblue}{rgb}{0.866,0.894,0.996}

\newcolumntype{B}[1]{>{\centering\arraybackslash\columncolor{myblue}}p{#1}}

\renewcommand{\arraystretch}{2}

\begin{document}

\begin{table}[!htb]
\begin{tabular}{ B{0.2\textwidth} | B{0.2\textwidth} }
title column 1 & title column 2 \\ \hline
content & content with binomial coefficient $\begin{pmatrix} n \\ k \end{pmatrix}$ \\
\end{tabular}
\end{table}

\end{document}

I have used \arraystretch to increase the height of the rows of my table. The problem is that, when I write a binomial coefficient in a cell using \begin{pmatrix}...\end{pmatrix}, the parenthesis are too large. The command \arraystretch seems to affect the environment pmatrix. How can I keep the row height and have a binomial coefficient which looks nice ?

Moreover, \arraystretch modifies the space between and after the text in all the cells. How can I modifiy this space locally, for one given row ?

2
  • Why you not use \binom{n}{k} instead \begin{pmatrix} n \\ k \end{pmatrix}? On it arraystretch doesn't has influence.
    – Zarko
    Sep 21, 2015 at 23:08
  • @Zarko : Thank you for the advice ! I didn't know \binom.
    – pitchounet
    Sep 21, 2015 at 23:15

2 Answers 2

2

enter image description here

\documentclass[10pt,a4paper]{article}
\usepackage{color}
\usepackage{amsmath}
\usepackage{colortbl}
\usepackage{array}
\definecolor{myblue}{rgb}{0.866,0.894,0.996}
\newcolumntype{B}[1]{>{\centering\arraybackslash\columncolor{myblue}}p{#1}}
\setlength{\extrarowheight}{50pt}

\begin{document}
\begin{table}[!htb]
\begin{tabular}{ B{0.2\textwidth} | B{0.2\textwidth} }
title column 1 & title column 2 \\[50pt] \hline
content & content with binomial coefficient  {\setlength{\extrarowheight}{0pt} $\begin{pmatrix} n \\ k \end{pmatrix}$} \\ [50pt]
\end{tabular}
\end{table}
\end{document}

Since you need the distance above the \hline to be equal to that below it, you should add \setlength{\extrarowheight}{50pt} to control the distance above and add \\ [50pt] with the same value 50pt to control the distance below.

To cancel the effect within a math array, just issue the command \setlength{\extrarowheight}{0pt} to neutralize the previous setting. Alternatively, you can apply @Zacro's advice and use \binom{n}{k} instead of \begin{pmatrix} n\\k \end{pmatrix}. The latter does not get affected by \extrarowheight.

4
  • Thank you ! I have solved my problem by ending each line (except the last one) of the table with \rule{0pt}{1cm} \rule[-1cm]{0pt}{0cm} \\ \hline. This allows me to set a blank space before and after each line. However, one cell contains \parbox{0.2\textwidth}{content1 \\ content2} to force a linebreak in a cell. If I end the corresponding line with \rule{0pt}{1cm} \rule[-1cm]{0pt}{0cm} \\ \hline, I get an enormous blank space before the horizontal \hline. Do you know where this is coming from?
    – pitchounet
    Sep 21, 2015 at 23:58
  • I solved this issue.
    – pitchounet
    Sep 22, 2015 at 0:20
  • Glad to hear that. Take care, though, your solution will not work for multi-line cells.
    – AboAmmar
    Sep 22, 2015 at 0:28
  • I think it works, even for multi-lines cells : I replaced \parbox{0.2\textwidth}{content1 \\ \content2} \rule{0pt}{1cm} \rule[-1cm]{0pt}{0cm} \\ \hline with : \parbox{0.2\textwidth}{ \content1 \rule{0pt}{1cm} \\ content2 \rule[-1cm]{0pt}{0cm} } \\ \hline. This would work even if I had two line-breaks inside \parbox. I would have to put \rule{0pt}{1cm} before the first \\ and \rule[-1cm]{0pt}{0cm} before closing the parbox. Thank you for your help !
    – pitchounet
    Sep 22, 2015 at 7:31
1

You can normalize the factor inside the table cells:

\newcolumntype{B}[1]{>{%
\renewcommand{\arraystretch}{1}%
\centering\arraybackslash\columncolor{myblue}}p{#1}}

so that the value of 2 is only used at the outer level.

Moreover, \arraystretch modifies the space between and after the text in all > the cells. How can I modifiy this space locally, for one given row ?

if you just want to change one row, do not change \arraystretch anywhere, leave it as 1, and just use \\[5cm] to have extra space after the spacial row.

2
  • Thank you ! In my table, each row ends with \\ \hline. If I use \\[1cm] instead of \\, it will increase the space before the horizontal rule. What I would like is to equally increase the space before the rule and after the rule (if there is another row after this one). Something like : \\[1cm] \hrule \vspace{1cm} does not work.
    – pitchounet
    Sep 21, 2015 at 23:13
  • put \rule{0pt}{5cm} at the start of the next row after \hline in that case. Sep 21, 2015 at 23:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .