我已看到与此问题相关的其他帖子,但我无法将表格的最后一列垂直居中:
\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}
显然,(\centering)\arraybackslash
这里没有解决方案。
编辑:
我不知道这是否可行,但我会编辑我的问题以回应 CarLaTeX 的回答。我最终想要做的是
\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}
但垂直居中。根据 CarLateX 关于列的最小宽度的建议,
\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}
我明白了
例如。但是,当然,我不希望第一列与第二列一样长。
另外,我该如何将文本刷新到节点左侧?使用anchor = west,可以锚定节点而不是文本。
答案1
添加一个非常大的支柱:
\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}
答案2
或者,您可以尝试 TikZ matrix of math nodes
。
也许您必须根据单元格的实际内容来调整text width
或其他选项,如text height
和。text depth
\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}
答案3
array
在每个表格行的末尾rule
都有:strut
\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}