# Fix on Weird Vertical Alignment of Multicols

What I have is the following code.

\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}


The code above compiles multicols as I attached below.

However, I want it to be vertically centred. How can I achieve that? I'm looking for any alternative, not necessarily to use multicols. I'd also appreciate it if the fix either centring both the table and equation vertically or horizontally, which I have zero clue to do. Thanks in advance.

• Off-topic: By using an array environment instead of a tabular environment, you could save yourself from having to input 7*5 = 35 instances of both $$ and $$.
– Mico
Jun 21, 2023 at 17:12

Using multicols for printing things side-by-side is not the right tool: multicols is meant to print longer text in multiple columns.

You can use $...$, with an array and 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}


You can also exploit that the two alignments on the right side have similar shapes, so easing the input.

\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}


• Cool! Thanks for the very big help and insight. Jun 22, 2023 at 3:13

Using the machinery of the multicol package seems like overkill for the use case at hand. I would like to suggest that you place an array environment on the left (no need to encase it in a table environment) and an alignedat environment on the right. Then, enclose both in a center environment to add a bit of whitespace above and below the math-y material.

\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}