![修复多列奇怪的垂直对齐问题](https://linux22.com/image/466215/%E4%BF%AE%E5%A4%8D%E5%A4%9A%E5%88%97%E5%A5%87%E6%80%AA%E7%9A%84%E5%9E%82%E7%9B%B4%E5%AF%B9%E9%BD%90%E9%97%AE%E9%A2%98.png)
我有下面的代码。
\begin{multicols}{2}
\begin{table}[H]
\centering
\begin{tabular}{ccccc}
\toprule
\(k\) & \(x_{k}\) & \(y_{k}\) & \(x_{k}y_{k}\) & \(x_{k}^{2}\) \\
\cmidrule(lr){1-1} \cmidrule(lr){2-5}
\(1\) & \(0\) & \(2\) & \(0(2)\) & \(0^{2}\) \\
\(2\) & \(1\) & \(3\) & \(1(3)\) & \(1^{2}\) \\
\(3\) & \(2\) & \(5\) & \(2(5)\) & \(2^{2}\) \\
\(4\) & \(3\) & \(4\) & \(3(4)\) & \(3^{2}\) \\
\(5\) & \(4\) & \(6\) & \(4(6)\) & \(4^{2}\) \\
\cmidrule(lr){1-1} \cmidrule(lr){2-5}
\(\sum\nolimits\) & \({\color{Salmon}10}\) & \({\color{Salmon}20}\) & \({\color{Salmon}49}\) & \({\color{Salmon}30}\) \\
\bottomrule
\end{tabular}
\end{table}
\columnbreak
\begin{align*}
\alpha &= \frac{
\det\begin{pmatrix}
\color{Salmon}30 & \color{Salmon}49 \\
\color{Salmon}10 & \color{Salmon}20
\end{pmatrix}
}{
\det\begin{pmatrix}
\color{Salmon}30 & \color{Salmon}10 \\
\color{Salmon}10 & 5
\end{pmatrix}
} & \beta &= \frac{
\det\begin{pmatrix}
\color{Salmon}49 & \color{Salmon}10 \\
\color{Salmon}20 & 5
\end{pmatrix}
}{
\det\begin{pmatrix}
\color{Salmon}30 & \color{Salmon}10 \\
\color{Salmon}10 & 5
\end{pmatrix}
} \\
&= \frac{30(20)-10(49)}{30(5)-10(10)} & &= \frac{49(5)-20(10)}{30(5)-10(10)} \\
&= 2.2, & &= 0.9.
\end{align*}
\end{multicols}
上面的代码multicols
按照我下面所附的方式进行编译。
但是,我希望它垂直居中。我该如何实现呢?我正在寻找任何替代方案,不一定非要使用multicols
。如果修复方法是将表格和方程垂直或水平居中,我将不胜感激,但我完全不知道该怎么做。提前致谢。
答案1
使用multicols
并排打印工具并不是正确的选择:multicols
它旨在在多列中打印较长的文本。
您可以将\[...\]
, 与array
和 一起使用aligned
。
\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage[dvipsnames]{xcolor}
\usepackage{showframe}% just for the example
\begin{document}
\[
\begin{array}{ccccc}
\toprule
k & x_{k} & y_{k} & x_{k}y_{k} & x_{k}^{2} \\
\cmidrule(lr){1-1} \cmidrule(lr){2-5}
1 & 0 & 2 & 0(2) & 0^{2} \\
2 & 1 & 3 & 1(3) & 1^{2} \\
3 & 2 & 5 & 2(5) & 2^{2} \\
4 & 3 & 4 & 3(4) & 3^{2} \\
5 & 4 & 6 & 4(6) & 4^{2} \\
\cmidrule(lr){1-1} \cmidrule(lr){2-5}
\sum & \color{Salmon}10 & \color{Salmon}20 & \color{Salmon}49 & \color{Salmon}30 \\
\bottomrule
\end{array}
\qquad
\begin{aligned}
\alpha &= \frac{
\det\begin{pmatrix}
\color{Salmon}30 & \color{Salmon}49 \\
\color{Salmon}10 & \color{Salmon}20
\end{pmatrix}
}{
\det\begin{pmatrix}
\color{Salmon}30 & \color{Salmon}10 \\
\color{Salmon}10 & 5
\end{pmatrix}
} &
\beta &= \frac{
\det\begin{pmatrix}
\color{Salmon}49 & \color{Salmon}10 \\
\color{Salmon}20 & 5
\end{pmatrix}
}{
\det\begin{pmatrix}
\color{Salmon}30 & \color{Salmon}10 \\
\color{Salmon}10 & 5
\end{pmatrix}
} \\
&= \frac{30(20)-10(49)}{30(5)-10(10)} & &= \frac{49(5)-20(10)}{30(5)-10(10)} \\
&= 2.2, & &= 0.9.
\end{aligned}
\]
\end{document}
您还可以利用右侧的两个对齐具有相似的形状,从而简化输入。
\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage[dvipsnames]{xcolor}
\usepackage{showframe}
\begin{document}
\[
\begin{array}{ccccc}
\toprule
k & x_{k} & y_{k} & x_{k}y_{k} & x_{k}^{2} \\
\cmidrule(lr){1-1} \cmidrule(lr){2-5}
1 & 0 & 2 & 0(2) & 0^{2} \\
2 & 1 & 3 & 1(3) & 1^{2} \\
3 & 2 & 5 & 2(5) & 2^{2} \\
4 & 3 & 4 & 3(4) & 3^{2} \\
5 & 4 & 6 & 4(6) & 4^{2} \\
\cmidrule(lr){1-1} \cmidrule(lr){2-5}
\sum & \color{Salmon}10 & \color{Salmon}20 & \color{Salmon}49 & \color{Salmon}30 \\
\bottomrule
\end{array}
\qquad
\begin{aligned}
\alpha &= \frac{
\det\begin{pmatrix}
\color{Salmon}30 & \color{Salmon}49 \\
\color{Salmon}10 & \color{Salmon}20
\end{pmatrix}
}{
\det\begin{pmatrix}
\color{Salmon}30 & \color{Salmon}10 \\
\color{Salmon}10 & 5
\end{pmatrix}
} \\
&= \frac{30(20)-10(49)}{30(5)-10(10)} \\
&= 2.2
\end{aligned}
\quad
\begin{aligned}
\beta &= \frac{
\det\begin{pmatrix}
\color{Salmon}49 & \color{Salmon}10 \\
\color{Salmon}20 & 5
\end{pmatrix}
}{
\det\begin{pmatrix}
\color{Salmon}30 & \color{Salmon}10 \\
\color{Salmon}10 & 5
\end{pmatrix}
} \\
&= \frac{49(5)-20(10)}{30(5)-10(10)} \\
&= 0.9.
\end{aligned}
\]
\end{document}
答案2
对于当前的用例来说,使用包的机制multicol
似乎有些过度。我建议您array
在左侧放置一个环境(无需将其包含在table
环境中),alignedat
在右侧放置一个环境。然后,将两者都包含在center
环境中,以在数学材料的上方和下方添加一些空白。
\documentclass{article} % or some other suitable document class
\usepackage{booktabs,amsmath}
\usepackage[dvipsnames]{xcolor} % for 'Salmon' color
\newcommand\Salmon{\color{Salmon}} % handy shortcut macro
\usepackage{lipsum} % filler text
\begin{document}
\begin{center}
$\begin{array}{@{}ccccc@{}} % use 'array', not 'tabular'
\toprule
k & x_{k} & y_{k} & x_{k}y_{k} & x_{k}^2 \\
\cmidrule(l){2-5}
1 & 0 & 2 & 0\cdot2 & 0^2 \\
2 & 1 & 3 & 1\cdot3 & 1^2 \\
3 & 2 & 5 & 2\cdot5 & 2^2 \\
4 & 3 & 4 & 3\cdot4 & 3^2 \\
5 & 4 & 6 & 4\cdot6 & 4^2 \\
\cmidrule(l){2-5}
\sum & \Salmon 10 & \Salmon 20 & \Salmon 49 & \Salmon 30 \\
\bottomrule
\end{array}$
\hfill % maximize the horizontal separation
$\begin{alignedat}{2}
\alpha &= \frac{
\det\begin{pmatrix}
\Salmon 30 & \Salmon 49 \\
\Salmon 10 & \Salmon 20
\end{pmatrix}}{
\det\begin{pmatrix}
\Salmon 30 & \Salmon 10 \\
\Salmon 10 & 5
\end{pmatrix}} &
\beta &= \frac{
\det\begin{pmatrix}
\Salmon 49 & \Salmon 10 \\
\Salmon 20 & 5
\end{pmatrix}}{
\det\begin{pmatrix}
\Salmon 30 & \Salmon 10 \\
\Salmon 10 & 5
\end{pmatrix}} \\
&= \frac{30\cdot20-10\cdot49}{30\cdot5-10\cdot10}
&\hspace{1cm} % insert horizontal whitespace
&= \frac{49\cdot5-20\cdot10}{30\cdot5-10\cdot10} \\
&= 2.2 & &= 0.9
\end{alignedat}$
\end{center}
\lipsum[1][1-7] % filler text
\end{document}