2

I have seen other posts related to this issue, but I haven't been able to vertically center the last column of my table:

\documentclass{article} 
\usepackage{amsmath}
\usepackage{array}
\usepackage[table]{xcolor}

\newcolumntype{L}{>{$}l<{$}} 
\newcolumntype{M}[1]{>{\raggedright\arraybackslash$}m{#1}<{$}}

%_________________________________


\begin{document}

    \rowcolors{1}{gray!5}{gray!15}

    \begin{tabular}{M{1cm} M{1cm} M{1cm}}
        a&b&c\\[14pt]
        u&v&w\\[14pt]
    \end{tabular}

\end{document}

enter image description here

Apparently, (\centering)\arraybackslash isn't the solution here.

Edit:

I don't know if this is the way to go, but I'll edit my question in response to CarLaTeX's answer. What I'm ultimately trying to do is

\documentclass{article} 
\usepackage{amsmath}
\usepackage{array}
\usepackage[table]{xcolor}

\newcolumntype{L}{>{$}l<{$}} 


\begin{document}

\rowcolors{1}{gray!5}{gray!15}
\begin{tabular}{L L}
    %
    (1+x)^{\alpha}
    &=1+ \alpha x+\frac{\alpha(\alpha-1)}{2!}x^{2}+\cdots+\frac{\alpha(\alpha-1)\cdots(\alpha-n+1)}{n!}x^{n}+\mathcal{O}\left(x^{n+1}\right)
    \\[14pt]
    %
    \frac{1}{\sqrt{1+x}}
    &=1-\frac{x}{2}+\frac{3}{8}x^{2}-\cdots+(-1)^{n}\frac{1\times 3\times\cdots.\times.(2n-1)}{2\times 4\times\cdot\times 2n}x^{n}+\mathcal{O}\left(x^{n+1}\right)
    \\[14pt]
\end{tabular}

\end{document}

enter image description here

but vertically centered. Following CarLateX's suggestion regarding the minimum width of the columns,

\documentclass{article} 
\usepackage{amsmath}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{
    mymatrix/.style = {
        matrix of math nodes, 
        nodes={inner ysep=7pt, minimum width=4cm, text height=2ex, text depth=.75ex},
        every odd row/.style={nodes={fill=gray!5}},
        every even row/.style={nodes={fill=gray!15}},
        row sep=-\pgflinewidth, 
        column sep=-\pgflinewidth, 
        inner sep=0pt
    },
}

\begin{document}




    \begin{tikzpicture}
\matrix[mymatrix]{
    (1+x)^{\alpha}
    &=1+ \alpha x+\frac{\alpha(\alpha-1)}{2!}x^{2}+\cdots+\frac{\alpha(\alpha-1)\cdot\ldots\cdot(\alpha-n+1)}{n!}x^{n}+\mathcal{O}\left(x^{n+1}\right)
    \\
    %
    \frac{1}{\sqrt{1+x}}
    &=1-\frac{x}{2}+\frac{3}{8}x^{2}-\ldots+(-1)^{n}\frac{1\times 3\times\ldots\times(2n-1)}{2\times 4\times\ldots\times 2n}x^{n}+\mathcal{O}\left(x^{n+1}\right)
    \\  };
\end{tikzpicture}   

\end{document}

I get

enter image description here

for example. But, of course, I don't want the 1st column to be as long as the second.

Also, how would I flush the text to the left of the nodes? Using anchor=west, well, anchors the node rather than the text.

  • 1
    This code produces all column cells vertically centred. There must be something else. – Bernard Apr 23 '18 at 22:09
  • Are you saying that this code should work, or that it does? Because, pasting it in overleaf yields the same thing:overleaf.com/15745639rpywqvtqgwdb#/59901105 – Chris Apr 23 '18 at 22:37
  • For me, it works as expected. I even downloaded the Overleaf code and it compiles fine. Would there be a problem with Overleaf? – Bernard Apr 23 '18 at 22:41
  • 1
    note that this is fixed in current versions 2017-11-07 Frank Mittelbach <Frank.Mittelbach@latex-project.org> * array.dtx: fixed bug reported on stack exchange SX68732 about bad vertical placement with last column being an m-column – David Carlisle Apr 23 '18 at 22:46
3

Add a very big strut:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage[table]{xcolor}

\newcolumntype{L}{>{$\bigggstrut}l<{$}}
\newcommand{\bigggstrut}{\vphantom{\left|\vbox to 18pt{}\right.}}


\begin{document}

\rowcolors{1}{gray!5}{gray!15}
\begin{tabular}{LL}
(1+x)^{\alpha}
&=1+\alpha x+\frac{\alpha(\alpha-1)}{2!}x^{2}+\dots
   +\frac{\alpha(\alpha-1)\dots(\alpha-n+1)}{n!}x^{n}
   +\mathcal{O}(x^{n+1})
\\
\dfrac{1}{\sqrt{1+x}}
&=1-\frac{x}{2}+\frac{3}{8}x^{2}-\dots
  +(-1)^{n}\frac{1\times 3\times\dots\times(2n-1)}
                {2\times 4\times\dots\times 2n}x^{n}
  +\mathcal{O}(x^{n+1})
\end{tabular}

\end{document}

enter image description here

3

As an alternative, you could try a TikZ matrix of math nodes.

Maybe you'll have to adjust the text width or other options like text height and text depth according to the actual content of the cells.

\documentclass{article} 
\usepackage{amsmath}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{
    mymatrix/.style = {
        matrix of math nodes, 
        nodes={
            inner ysep=7pt,
            inner xsep=0pt,  
            text height=4ex, text depth=2ex
        },
        column 1/.style={nodes={text width=4em, align=right}},
        column 3/.style={nodes={text width=30em, align=left}},
        every odd row/.style={nodes={fill=gray!5}},
        every even row/.style={nodes={fill=gray!15}},
        row sep=-\pgflinewidth, 
        column sep=-\pgflinewidth, 
        inner sep=0pt
    },
}


\begin{document}


    \begin{tikzpicture}
    \matrix[mymatrix]{
        (1+x)^{\alpha}
        &{}={}& 1 + \alpha x + \dfrac{\alpha(\alpha-1)}{2!}x^{2} + \dotsm + \dfrac{\alpha(\alpha-1)\dotsm(\alpha-n+1)}{n!}x^{n} + \mathcal{O}\left(x^{n+1}\right)     \\
        \dfrac{1}{\sqrt{1+x}}
        &{}={}& 1 - \dfrac{x}{2} + \dfrac{3}{8}x^{2} - \cdots+(-1)^{n}\dfrac{1\times 3\times\dotsm\times(2n-1)}{2\times 4\times\dotsm\times 2n} x^{n} + \mathcal{O}\left(x^{n+1}\right) \\
    };
    \end{tikzpicture}

 \end{document}

enter image description here

  • Thanks for your input. But if you type 'text text text' instead of say 'b', although the cell will adjust, the one beneath it won't. Any work around? – Chris Apr 24 '18 at 8:15
  • @Chris You have already other very good answers, however, I edited my answer to solve the problem. – CarLaTeX Apr 24 '18 at 20:22
  • Thanks! Off topic: I am fairly new to posting here, so, if you'd know: should I undo my previous edit so as to make the question more concise, or keep its 'history'? – Chris Apr 26 '18 at 18:54
  • @Chris No, leave it as is. It's OK :) – CarLaTeX Apr 26 '18 at 18:55
2

with array and rule as strut on the end of the each table row:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage[table]{xcolor}

\begin{document}

\rowcolors{1}{gray!5}{gray!15}
\[
    \begin{array}{r@{\;} l<{\rule[-2em]{0pt}{4.5em}}}
(1+x)^{\alpha}
    & = 1 + \alpha x + \dfrac{\alpha(\alpha-1)}{2!}x^{2} + \dotsm + \dfrac{\alpha(\alpha-1)\dotsm(\alpha-n+1)}{n!}x^{n} + \mathcal{O}\left(x^{n+1}\right)     \\
\dfrac{1}{\sqrt{1+x}}
     & = 1 - \dfrac{x}{2} + \dfrac{3}{8}x^{2} - \cdots+(-1)^{n}\dfrac{1\times 3\times\dotsm\times(2n-1)}{2\times 4\times\dotsm\times 2n} x^{n} + \mathcal{O}\left(x^{n+1}\right)
\end{array}
\]
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.