1

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

enter image description here

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}

enter image description here

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}

enter image description here

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.

Nasser
  • 20,220

2 Answers2

1

See https://tex.stackexchange.com/a/319775/161015 for a patch and put \makegapedcells inside the environment instead of the preamble.

Try the code:

\documentclass[12pt]{book}

\usepackage{array}
\usepackage{makecell} %make sure before arydshln

%%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}
\setcellgapes{5pt} %added march 14,2021 \makegapedcells % put it here <<<<<<<<<<<<<<<<<<<<<<

\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}

b

Simon Dispa
  • 39,141
  • Thanks. But after testing it more, the patch does not work. I still get same error as before. In your posted example, you did not include \makegapedcells and that is why you did not see the compile error. Also, \arraystretch does not really work. I'll post an example showing this. – Nasser Apr 13 '21 at 06:56
  • @Nasser Please note that \makegapedcells IS included, albeit after \begin{document} not in the preamble. – Simon Dispa Apr 13 '21 at 13:21
  • FYI, it works in preamble, but needed to add \makegapedcells after patch code, n ot before it. Thanks. – Nasser Apr 13 '21 at 19:41
1

I recommend nicematrix with its key cell-space-limits which is compatible with the columns of type m.

\documentclass[12pt]{article}

\usepackage{nicematrix} \NiceMatrixOptions{cell-space-limits=5pt}

\begin{document}

\begin{center}% \begin{NiceTabular}[c]{lll}[hvlines] Spin matrix & Eigenvalues & Eigenvectors\ $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} $\ \end{NiceTabular} \end{center}

\begin{center} \begin{NiceTabular}[c]{>{\raggedright}m{4cm}ll}[hvlines] Spin matrix & Eigenvalues & Eigenvectors\ blah blah blah blah blah blah blah blah blah blah blah blah blah blah & $\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} $\ \end{NiceTabular} \end{center}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250