Makecell: how to reduce the line spacing in multiline cells

line-spacingtables

The following LaTeX source code

\documentclass[12pt]{article}
\usepackage{makecell}
\begin{document}

\begin{tabular}{ll}
    foobar                    & 0  \\
    foo                       & 1  \\
    \makecell[tl]{bar plus \\
                  other    \\
                  stuff}      & 2  \\
    baz                       & 3  \\
    qux                       & 4  \\
    quux                      & 5  \\
\end{tabular}

\end{document}

…produces the following rendering:

enter image description here

This is almost what I want, but I would like that the spacing between the lines in the multiline cell ("bar plus other stuff") be noticeably smaller than the spacing between table's rows.

Therefore, I tried adding \renewcommand{\arraystretch}{1.3} right before the \begin{tabular}[ll} line1; i.e.:

\renewcommand{\arraystretch}{1.3}
\begin{tabular}{ll}
    foobar                    & 0  \\
    foo                       & 1  \\
    \makecell[tl]{bar plus \\
                  other    \\
                  stuff}      & 2  \\
    baz                       & 3  \\
    qux                       & 4  \\
    quux                      & 5  \\
\end{tabular}

Here's what the results look like:

enter image description here

After seeing this, I realized that I would like to keep the between-rows spacing as it was before (i.e. as it was before I added \renewcommand{\arraystretch}{1.3}), and instead make the spacing between the lines in the multiline cell narrower2.

I have read, and re-read, and re-read once more, the documentation for the makecell package, but I just cannot make heads or tails of it. (Nothing that I have copied verbatim from that documentation will even compile, let alone do what I'm after.) I'm sure that somewhere in that documentation is the information I need to change the spacing between the lines in the multiline cell. Could someone please spell it out for me?3


EDIT: I learned from @Bernard's helpful answer that the reason nothing worked for me when I tried customizing makecell's behavior is that I was missing the \usepackage{array} directive. With this knowledge in hand, I tried to get the tighest possible spacing between the lines of a multiline cell as follows:

\documentclass[12pt]{article}
\usepackage{array}
\usepackage{makecell}
\renewcommand\cellset{\renewcommand\arraystretch{0}%
\setlength\extrarowheight{0pt}}

\begin{tabular}{ll}
    foobar                    & 0  \\
    foo                       & 1  \\
    \makecell[tl]{bar plus \\
                  other    \\
                  stuff}      & 2  \\
    baz                       & 3  \\
    qux                       & 4  \\
    quux                      & 5  \\
\end{tabular}

\end{document}

The results:

enter image description here

Granted, the between-line spacing resulting from this particular directive may be a bit too tight; probably a slightly looser spacing (but still tighter than the spacing between rows) would be better. Nevertheless, I use this extreme case to better illustrate the remaining problem: namely the newly added directive

\renewcommand\cellset{\renewcommand\arraystretch{0}%
\setlength\extrarowheight{0pt}}

…affects not only the spacing between the lines in the multiline cell (as desired), but also the spacing between the last line of the multiline cell ("stuff") and the next row ("baz  3"), which is definitely not what I want4.

Is there a way to tweak this latest version (based on makecell5) so that only the spacing between the lines in the multiline cells is reduced, but all the other vertical spacing, including the spacing between the last line of the multiline cell ("stuff") and the next row ("baz  3") are preserved?


EDIT 2: Actually, the issue in my last edit can be understood more clearly if one replaces all the entries in the first column with a common string, e.g. "0000". Hence, if we change the document's body to

\begin{tabular}{ll}
    0000                      & 0  \\
    0000                      & 1  \\
    \makecell[tl]{0000 \\
                  0000 \\
                  0000}       & 2  \\
    0000                      & 3  \\
    0000                      & 4  \\
    0000                      & 5  \\
\end{tabular}

…leaving everything else unchanged, the result looks like this:

enter image description here

In words: the newly added directive does reduce the spacing between the lines in the multiline cell, but it also reduces the spacing between the last line of the multiline cell and the next row (the one with "3" in the second colum). Granted, this latter spacing is slightly larger than the former, but it is still significantly smaller than the spacing between the remaining rows.


EDIT 3: As I mentioned earlier, I have not found a combination of parameters that for the new directive that will produce the desired results. For example, the result I get from the source code below (where I've changed \extrarowheight's parameter to 1pt) looks to me exactly the same as the one I showed in the last display above.

\documentclass[12pt]{article}
\usepackage{array}
\usepackage{makecell}
\renewcommand\cellset{\renewcommand\arraystretch{0}%
\setlength\extrarowheight{1pt}} %% NB: I see no difference in results
                                %% between 0pt and 1pt

\begin{document}

\begin{tabular}{ll}
    0000                      & 0  \\
    0000                      & 1  \\
    \makecell[tl]{0000 \\
                  0000 \\
                  0000}       & 2  \\
    0000                      & 3  \\
    0000                      & 4  \\
    0000                      & 5  \\
\end{tabular}

\end{document}

1 If I understand correctly, the way I've added the \renewcommand{\arraystretch}{1.3} directive means that it will affect all the subsequent code, up until the end of the file. Just curious: is there a way that I can limit the effect of this directive to just the one table?

2 I realize that making the line spacing in the multiline cell narrower will make the text look cramped. That's OK. In practice, I expect multiline cells will be quite rare. Therefore, I prefer a solution that keeps the normal case (rows consisting entirely of single-line cells) looking nice, even if the occasional multiline cell ends up looking cramped.

3 Asking such a question is deeply embarrassing for me. I have been programming for a living for >30 years, and I have been using LaTex pretty much all that time. I have written dozens of reports and scientific papers, and one doctoral dissertation, with LaTeX. I have read books on LaTeX cover-to-cover. Even with all this experience and study, I still find LaTeX utterly mystifying. (And please let's not talk about TeX…) This is particularly true of the documentation of the typical LaTeX package, as illustrated by my complete failure to find even an approximation to the answer to my question in the documentation for the makecell package. I hope that, in addition to solving my immediate problem, the answer to this question may teach me a bit how to find my way around LaTeX documentation.

4 For what it's worth, I have not found a combination of parameter values to stick into the \renewcommand\cellset{\renewcommand\arraystretch{...}\setlength\extrarowheight{...}} directive that simultaneously solves the original problem, and whose result does not suffer from the defect illustrated in the last display above.

5 I realize, after reading @Zarko's also very helpful answer, that makecell is probably not the best package for what I'm trying to do, and therefore, that by insisting on using makecell for this, I am probably making this problem unnecessarily difficult. Unfortunately, it appears that tabularray requires a newer installation of LaTeX than what I have in my system. This means that, until I figure out how to upgrade the LaTeX installation on my system, something that has eluded me for weeks already, I am basically stuck with makecell.

Best Answer

Does this solution with only makecell befit you?

    \documentclass{article}
    \usepackage{array, makecell}
    \renewcommand\cellset{\renewcommand\arraystretch{0.8}%
    \setlength\extrarowheight{0pt}}

    \begin{document}

    \renewcommand{\arraystretch}{1.3}
    \begin{tabular}{ll}
        foobar & 0 \\
        foo & 1 \\
        \makecell[tl]{bar plus \\
                      other \\
                      stuff} & 2 \\
        baz & 3 \\
        qux & 4 \\
        quux & 5 \\
    \end{tabular}

    \end{document} 

enter image description here