I added the command \makegapedcells from package makecell and now my tabular gives error when using m for fields.
There seems to be some conflict. Here is MW.
\documentclass[12pt]{book}
\usepackage{array}
\usepackage{makecell} %make sure before arydshln
%see https://tex.stackexchange.com/questions/563115/how-to-add-more-padding-to-table-rows-when-table-has-array-inside-it
\setcellgapes{5pt} %added march 14,2021
\makegapedcells %added march 14,2021
\begin{document}
\begin{tabular}[c]{|m{2in}|m{4in}|}\hline
cell 1
&
cell 2
\end{tabular}
\end{document}
Now, lualatex foo5.tex gives
(base) >lualatex foo5.tex
This is LuaHBTeX, Version 1.12.0 (TeX Live 2020)
restricted system commands enabled.
(./foo5.tex
LaTeX2e <2020-10-01> patch level 2
L3 programming layer <2020-12-07> xparse <2020-03-03> (/usr/local/texlive/2020/texmf-dist/tex/latex/base/book.cls
Document Class: book 2020/04/10 v1.4m Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/bk12.clo)) (/usr/local/texlive/2020/texmf-dist/tex/latex/tools/array.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/makecell/makecell.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-luatex.def) (./foo5.aux) (/usr/local/texlive/2020/texmf-dist/tex/latex/base/ts1cmr.fd)
! Missing $ inserted.
<inserted text>
$
l.11 c
ell 1
?
If I change m in the table to p, the error goes away. Also, if I remove the command \makegapedcells, the error goes away.
Why does this happen? Is this a bug? or Am I not using it correctly?
I am using \makegapedcells to get more space between rows as documented in the package makecell
I know as a workaround, I could do the following
\documentclass[12pt]{book}
\usepackage{array}
\usepackage{makecell} %make sure before arydshln
\setcellgapes{5pt} %added march 14,2021
\begin{document}
\begin{tabular}[c]{|m{2in}|m{4in}|}\hline
\makegapedcells
cell 1
&
cell 2
\end{tabular}
\end{document}
And now it compiles. But I have 100's of tables in many files, and I do not want to search for each and change it like the above. so that is why I used \makegapedcells in the preamble.
reference:
https://ctan.math.illinois.edu/macros/latex/contrib/makecell/makecell.pdf
edit 4/13/2021
The patch posted in answer below does not work. I still get same error
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{makecell}
\setcellgapes{5pt}
\makegapedcells %I need to add this to make cell spacing larger.
%%FROM https://tex.stackexchange.com/questions/319768/are-m-column-type-and-makecell-incompatible
\makeatletter
\renewcommand\mcell@classz{@classx
@tempcnta \count@
\prepnext@tok
@addtopreamble{%\mcell@mstyle
\ifcase@chnum
\hfil
\mcell@agape{\d@llarbegin\insert@column\d@llarend}\hfil \or
\hskip1sp
\mcell@agape{\d@llarbegin\insert@column\d@llarend}\hfil \or
\hfil\hskip1sp
\mcell@agape{\d@llarbegin \insert@column\d@llarend}\or
\mcell@agape{$\vcenter
@startpbox{@nextchar}\insert@column@endpbox$}\or
\mcell@agape{\vtop
@startpbox{@nextchar}\insert@column@endpbox}\or
\mcell@agape{\vbox
@startpbox{@nextchar}\insert@column@endpbox}%
\fi
\global\let\mcell@left\relax\global\let\mcell@right\relax
}\prepnext@tok}
\makeatletter
\begin{document}
\begin{tabular}[c]{|m{2in}|m{4in}|}\hline
cell 1
&
cell 2
\end{tabular}
\end{document}
gives
lualatex foo5.tex
This is LuaHBTeX, Version 1.12.0 (TeX Live 2020)
restricted system commands enabled.
(./foo5.tex
LaTeX2e <2020-10-01> patch level 2
L3 programming layer <2020-12-07> xparse <2020-03-03> (/usr/local/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size12.clo)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/makecell/makecell.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/tools/array.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-luatex.def) (./foo5.aux) (/usr/local/texlive/2020/texmf-dist/tex/latex/base/ts1cmr.fd)
! Missing $ inserted.
<inserted text>
$
l.37 c
ell 1
?
Also, arraystretch does not really work. I need to have extra space added in the cell. Here is an example showing it does not work
\documentclass[12pt]{article}
\usepackage{amsmath}
\renewcommand{\arraystretch}{3}% does not work
\begin{document}
\begin{center}%
\begin{tabular}[c]{|l|l|l|}\hline
Spin matrix & Eigenvalues & Eigenvectors\\hline
$S_{x}=\frac{\hbar}{2}%
\begin{bmatrix}
0 & 1\
1 & 0
\end{bmatrix}
$ & $\frac{\hbar}{2},-\frac{\hbar}{2}$ & $\frac{1}{\sqrt{2}}%
\begin{bmatrix}
1\
1
\end{bmatrix}
\qquad\frac{1}{\sqrt{2}}%
\begin{bmatrix}
-1\
1
\end{bmatrix}
$\\hline
\end{tabular}
\end{center}%
\end{document}
Compare to when using usepackage{makecell}
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{makecell}
\setcellgapes{5pt}
\makegapedcells %works as long as m is not used
\begin{document}
\begin{center}%
\begin{tabular}[c]{|l|l|l|}\hline
Spin matrix & Eigenvalues & Eigenvectors\\hline
$S_{x}=\frac{\hbar}{2}%
\begin{bmatrix}
0 & 1\
1 & 0
\end{bmatrix}
$ & $\frac{\hbar}{2},-\frac{\hbar}{2}$ & $\frac{1}{\sqrt{2}}%
\begin{bmatrix}
1\
1
\end{bmatrix}
\qquad\frac{1}{\sqrt{2}}%
\begin{bmatrix}
-1\
1
\end{bmatrix}
$\\hline
\end{tabular}
\end{center}%
\end{document}
The above is what I want. But I wanted it to work with the m option. So I am afraid answer below does not solve this problem. The patch still gives an error when using m option.
Edit 4/13/2021
After more experiments, \makegapedcells can be used in preamble, but has to be AFTER the patch. As follows
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{makecell}
\setcellgapes{5pt}
%%FROM https://tex.stackexchange.com/questions/319768/are-m-column-type-and-makecell-incompatible
\makeatletter
\renewcommand\mcell@classz{@classx
@tempcnta \count@
\prepnext@tok
@addtopreamble{%\mcell@mstyle
\ifcase@chnum
\hfil
\mcell@agape{\d@llarbegin\insert@column\d@llarend}\hfil \or
\hskip1sp
\mcell@agape{\d@llarbegin\insert@column\d@llarend}\hfil \or
\hfil\hskip1sp
\mcell@agape{\d@llarbegin \insert@column\d@llarend}\or
\mcell@agape{$\vcenter
@startpbox{@nextchar}\insert@column@endpbox$}\or
\mcell@agape{\vtop
@startpbox{@nextchar}\insert@column@endpbox}\or
\mcell@agape{\vbox
@startpbox{@nextchar}\insert@column@endpbox}%
\fi
\global\let\mcell@left\relax\global\let\mcell@right\relax
}\prepnext@tok}
\makeatletter
\makegapedcells % HAS to be AFTER the batch, else compiler error
\begin{document}
\begin{tabular}[c]{|m{2in}|m{4in}|}\hline
cell 1 & cell 2\ \hline
cell 3 & cell 4\ \hline
cell 5 & cell 6\ \hline
\end{tabular}
\end{document}
Now compiles OK
lualatex foo5.tex
This is LuaHBTeX, Version 1.12.0 (TeX Live 2020)
restricted system commands enabled.
(./foo5.tex
LaTeX2e <2020-10-01> patch level 2
L3 programming layer <2020-12-07> xparse <2020-03-03> (/usr/local/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size12.clo)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/makecell/makecell.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/tools/array.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-luatex.def) (./foo5.aux) (/usr/local/texlive/2020/texmf-dist/tex/latex/base/ts1cmr.fd)
Overfull \hbox (86.81996pt too wide) in paragraph at lines 35--40
[][]
[1{/usr/local/texlive/2020/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./foo5.aux))
(see the transcript file for additional information)
484 words of node memory still in use:
6 hlist, 2 vlist, 2 rule, 2 glue, 4 kern, 1 glyph, 6 attribute, 52 glue_spec, 6 attribute_list, 1 write nodes
avail lists: 2:91,3:28,4:1,5:21,6:14,7:210,8:1,9:164
</usr/local/texlive/2020/texmf-dist/fonts/opentype/public/lm/lmroman12-regular.otf>
Output written on foo5.pdf (1 page, 3677 bytes).
Transcript written on foo5.log.
Now I can use m type and also use \makegapedcells in preamble. I wanted to use this in preamble only for other reasons.





\makegapedcellsafter\begin{document}not in the preamble – Simon Dispa Apr 13 '21 at 13:53bmatrixso naturally\arraystretchwill not produce the desired result. – Simon Dispa Apr 13 '21 at 14:02