![居中对齐文本*](https://linux22.com/image/439126/%E5%B1%85%E4%B8%AD%E5%AF%B9%E9%BD%90%E6%96%87%E6%9C%AC*.png)
我有一个项目,我必须使用align*
,但我对它的肤浅感到困扰。
\begin{align*}
\span {n \choose n_{1}} &&\times&& {n-n_{1} \choose n_{2}} &&\times&& \cdots &&\times&& {n_{k} \choose n_{k}}\\
&= \frac{n!}{n_{1}!(n-n_{1})!} &&\times&& \frac{(n-n_{1})!}{n_{2}!((n-n_{1})!-n_{2})!} &&\times&& \cdots &&\times&& \frac{n_{k}!}{n_{k}!1!}\\
&= \frac{n!}{n_{1}!n_{2}! ... n_{k}!} \span\span\span\span\span\span
\end{align*}
对于上面的代码我得到这个输出:
但我想要一些东西,例如:
我试过了\centering
,但它不起作用,我试过了,\mkern+/-xmu
但它没有功能,如果改变文本大小或字体,那么表面结果也会改变。
答案1
您可以将内容设置为类似大小的框;这是使用\eqmathbox[<tag>][<align>]{<stuff>}
默认<align>
输入位置自动c
完成的。
\documentclass{article}
\usepackage{amsmath,eqparbox}
% https://tex.stackexchange.com/a/34412/5764
\makeatletter
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
\IfValueTF{#1}
{\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
{\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
\mathpalette\eqmathbox@{#3}
}
\makeatother
\begin{document}
\begin{alignat*}{4}
\eqmathbox[box1]{\binom{n}{n_1}} & {}\times{} &
\eqmathbox[box2]{\binom{n - n_1}{n_2}} & {}\times{} & \cdots & {}\times{} &
\eqmathbox[box3]{\binom{n_k}{n_k}} \\
= \eqmathbox[box1]{\frac{n!}{n_1! (n - n_1)!}} & {}\times{} &
\eqmathbox[box2]{\frac{(n - n_1)!}{n_2!((n - n_1)! - n_2)!}} & {}\times{} & \cdots & {}\times{} &
\eqmathbox[box3]{\frac{n_k!}{n_k!1!}} \\
= \eqmathbox[box1]{\frac{n!}{n_1! n_2! \dots n_k!}}
\end{alignat*}
\end{document}
答案2
您说您“必须使用 align”。但是,我看不出有什么理由不使用array
具有自动显示数学模式和两种自定义列类型的环境。哦,请使用\binom{...}{...}
而不是{ ... \choose ...}
。
\documentclass{article}
\usepackage{array} % for '\newcolumntype' macro
\newcolumntype{C}{>{\displaystyle}c} % automatic display-math mode
\newcolumntype{O}{>{{}}c<{{}}} % column type for math operators
\usepackage{amsmath} % for '\binom' macro
\begin{document}
\[
\setlength\arraycolsep{0pt}
\begin{array}{ *{4}{OC} }
& \binom{n}{n_{1}} &\times& \binom{n-n_{1}}{n_{2}} &\times& \cdots &\times& \binom{n_{k}}{n_{k}} \\[15pt]
= & \frac{n!}{n_{1}!\,(n-n_{1})!} &\times& \frac{(n-n_{1})!}{n_{2}!\,((n-n_{1})!-n_{2})!} &\times& \cdots &\times& \frac{n_{k}!}{n_{k}!\,1!} \\[12pt]
= & \frac{n!}{n_{1}!\,n_{2}! \dots n_{k}!}
\end{array}
\]
\end{document}
答案3
和array
:
\documentclass{article}
\begin{document}
\[\setlength\arraycolsep{2pt}
\begin{array}{*{8}{c}}
& {n \choose n_{1}} & \times & {n-n_{1} \choose n_{2}} & \times & \cdots &\times & {n_{k} \choose n_{k}} \\[2ex]
= & \frac{n!}{n_{1}!(n-n_{1})!} & \times & \frac{(n-n_{1})!}{n_{2}!((n-n_{1})!-n_{2})!} & \times & \cdots & \times & \frac{n_{k}!}{n_{k}!1!} \\[2ex]
= & \frac{n!}{n_{1}!n_{2}! ... n_{k}!}& & & & &
\end{array}
\]
\end{document}
编辑:
考虑@Mico 建议使用\displaymath
方程大小:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[\setlength\arraycolsep{1pt}
\begin{array}{*{8}{>{\displaystyle}c}}
& \binom{n}{n_{1}} & \times & \binom{n-n_{1}}{n_{2}} & \times & \cdots &\times & \binom{n_{k}}{n_{k}} \\[3ex]
= & \frac{n!}{n_{1}!(n-n_{1})!} & \times & \frac{(n-n_{1})!}{n_{2}!((n-n_{1})!-n_{2})!} & \times & \cdots & \times & \frac{n_{k}!}{n_{k}!1!} \\[3ex]
= & \frac{n!}{n_{1}!n_{2}! ... n_{k}!}& & & & &
\end{array}
\]
\end{document}
答案4
这是我的解决方案,后者与 Mico 的解决方案类似,但又有所不同。
\documentclass{article}
\usepackage{amsmath}
\usepackage{array,booktabs}
\begin{document}
I usually start from the assumption that readers can read,
pairing up the terms by themselves, so large white space
around operation symbols can be avoided.
\begin{multline*}
\binom{n}{n_{1}} \times \binom{n-n_{1}}{n_{2}} \times \dots \times \binom{n_{k}}{n_{k}} \\
\begin{aligned}
&= \frac{n!}{n_{1}!\,(n-n_{1})!} \times \frac{(n-n_{1})!}{n_{2}!\,((n-n_{1})-n_{2})!}
\times \cdots \times \frac{n_{k}!}{n_{k}!\,1!}\\
&= \frac{n!}{n_{1}!\,n_{2}! \dots n_{k}!}
\end{aligned}
\end{multline*}
However, you can center the corresponding terms, if you so prefer;
an accurate comparison will tell you which display to use.
\begin{equation*}
\setlength{\arraycolsep}{0pt} % let TeX do the spacing job
\begin{array}{
@{}
>{{}}c<{{}} % operator or relation
>{\displaystyle}c % term
>{{}}c<{{}} % operator or relation
>{\displaystyle}c % term
>{{}}c<{{}} % operator or relation
>{\displaystyle}c % term
>{{}}c<{{}} % operator or relation
>{\displaystyle}c % term
@{}
}
& \binom{n}{n_{1}} &\times& \binom{n-n_{1}}{n_{2}}
&\times& \dotsb &\times& \binom{n_{k}}{n_{k}} \\
\addlinespace
=& \frac{n!}{n_{1}!\,(n-n_{1})!} &\times& \frac{(n-n_{1})!}{n_{2}!\,((n-n_{1})-n_{2})!}
&\times& \dotsb &\times& \frac{n_{k}!}{n_{k}!\,1!} \\
\addlinespace
=& \multicolumn{7}{>{\displaystyle}l}{\frac{n!}{n_{1}!\,n_{2}! \dots n_{k}!}}
\end{array}
\end{equation*}
Some filler text at the end, with the repeated recommendation to use the first
display and not the second one. Oh, I fixed a wrong factorial removing it.
\end{document}
请阅读评论。