6

I have a long table where every single cell has to be formatted in math mode and enclosed between the same code, i.e. $\{\ldots,<cell>,\ldots\}$. To avoid repeating I'm using the feature from the array package that lets you specify code to be inserted before and after each cell contents, i.e. >{code}Mc<{code}.

However, this combines poorly with the \multirow command, because while the content of the spanning cell seems to be correctly centered between the two rows, the code is inserted twice. Furthermore, it seems I have to put content into math mode again to make it work.

Here is a minimal example:

\documentclass{standalone}

\usepackage{array}
\usepackage{multirow}

\begin{document}

    \newcolumntype{L}{>{$\{\ldots,} c <{,\ldots\}$}}

    \begin{tabular}{L L} \hline
        \alpha & \beta \\
        \multirow{2}{*}{$\gamma$} & \delta \\
                                  & \eta \\\hline
    \end{tabular}
\end{document}

with the result: mwe

So is it possible to combine \multirow with these kind of column specification?

2
  • So isn't there a badge for "You asked the first TeX.SE question that was not answered wonderfully in less than 20 minutes" ?? XD Jan 16, 2017 at 9:43
  • No, but the Tumbleweed badge is ahead :D
    – user31729
    Jan 18, 2017 at 13:18

2 Answers 2

3

The call \multirow{<n>}{*}{<text>} works essentially in this way:

  1. the argument <text> is typeset in a box;
  2. the boxed is shifted down to emulate centering with respect to <n> rows;
  3. the shifted box is handed to tabular.

It's only after step 3 that the pre-text and post-text are added. Such texts are also added when the cell is empty.

Note that \multirow is not aware at all about the column type. Not even of being in array rather than tabular. So the argument is always assumed in text mode.

So, if you plan to use \multirow in a column, either be prepared to use \multicolumn{1}{...}{...}{\multirow{2}{*}{...}} and \multicolumn{1}{c}{} for every empty cell or don't use pre-text and post-text in the column.

Annoying? Perhaps. But I've long come to the conclusion that tables very rarely, if ever, need \multirow.

\documentclass[border=4pt]{standalone}
\usepackage{amsmath}
\usepackage{array}
\usepackage{multirow}

\newcommand{\foo}[1]{$\{\dots,#1,\dotsc\}$}

\begin{document}

\begin{tabular}{c c}
\hline
\foo{\alpha} & \foo{\beta} \\
\multirow{2}{*}{\foo{\gamma}} & \foo{\delta} \\
             & \foo{\eta} \\
\hline
\end{tabular}

\end{document}

enter image description here

3
  • egreg, but in this way you have to change all the cell, with my dirty fix only the ones involved in the multirow...
    – CarLaTeX
    Mar 6, 2017 at 10:34
  • @CarLaTeX Sure! I just wanted to show what I believe is a cleaner method, albeit heavier to use.
    – egreg
    Mar 6, 2017 at 10:52
  • I also think that this is more elegant, but if the actual table has a lot of cells it's not convenient. Let's see what the OP preferes :):):)
    – CarLaTeX
    Mar 6, 2017 at 10:58
2

I don't know if this solution could be acceptable for you, but I've used a couple of fake multicolumns and explicity added the post/pre code to the multirow.

I've also added a couple of rows just to show that you don't need to modify the single rows.

\documentclass{standalone}

\usepackage{array}
\usepackage{multirow}

\begin{document}

    \newcolumntype{L}{>{$\{\ldots,} c <{,\ldots\}$}}

    \begin{tabular}{L L} \hline
        \alpha & \beta \\
        \multicolumn{1}{c}{\multirow{2}{*}{$\{\ldots, \gamma ,\ldots\}$}} & \delta \\
        \multicolumn{1}{c}{} & \eta \\
        \alpha & \beta \\
        \alpha & \beta \\
        \hline
    \end{tabular}
\end{document}

enter image description here

You must log in to answer this question.

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