Array dentro de um tabular de 3 colunas
Estou tendo um tabular com 3 colunas. Dentro de cada coluna, estou tentando usar uma matriz. Mas, todas as matrizes estão vindo na primeira coluna.
Código:
\documentclass[12 pt, a4paper]{book}
\usepackage{multicol}
\usepackage{geometry}
\geometry{
a4paper,
total={170 mm,257 mm},
left=20 mm,
top=20 mm,
}
\usepackage{amsmath,bm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{soul}
\usepackage{indentfirst}
\usepackage[utf8]{inputenc}
\usepackage{palatino}
\usepackage[dvipsnames]{xcolor}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{enumitem}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{arydshln}
\usepackage{calc}
\setlength{\parindent}{2em}
\newcommand{\wt}[2]{\underset{\substack{\textstyle\uparrow\\\hidewidth\mathstrut#2\hidewidth}}{#1}}
\definecolor{mygray}{gray}{0.6}
\begin{document}
\textbf{Solution :} \\[0.5 cm]
\hspace*{0.5 cm}
\setlength\arraycolsep{0.2em}
\setlength{\tabcolsep}{2em}
\begin{tabular}{c | c | c}
(a) 9's complement :\\[0.25 cm]
$\begin{array}{ccccc} & 9 & 9 & 9 & 9 \\ - & 5 & 8 & 4 & 2 \\ \cline{2-5} & 4 & 1 & 5 & 7 \end{array}$ &
(b) 7's complement :\\[0.25 cm]
$\begin{array}{ccccc} & 7 & 7 & 7 & 7 \\ - & 6 & 4 & 2 & 3 \\ \cline{2-5} & 1 & 3 & 5 & 4 \end{array}$ &
(c) 15's complement :\\[0.25 cm]
$\begin{array}{ccccc} & \mathrm{F} & \mathrm{F} & \mathrm{F} & \mathrm{F} \\ - & \mathrm{A} & 9 & 6 & \mathrm{D} \\ \cline{2-5} & 5 & 6 & 9 & 2 \end{array}$
\end{tabular}
\end{document}
Produto obtido:
A saída obtida para o código acima é:
Resultado desejado:
A saída desejada é:
Alguém pode me ajudar a resolver isso? Forneça uma solução padrão, que funcione também para diferentes dimensões de array.
Respostas
A matriz deve estar na 2ª linha da tabela. No entanto, sugiro usar o taskspacote e seu ambiente de mesmo nome para uma sintaxe mais natural.
Não relacionado : Eu removi pacotes já carregados por outros pacotes (por exemplo, amsfonts é carregado por amssymb, amsmath é carregado por mathtools). Observe que utf8 agora deve ser a codificação de entrada por padrão. Usar o matrixambiente no lugar de array simplifica um pouco o código. Além disso, as regras de booktabstêm algum preenchimento vertical. Usei-os no código com tarefas.
\documentclass[12 pt, a4paper]{book}
\usepackage{multicol}
\usepackage{geometry}
\geometry{
a4paper,
total={170 mm,257 mm},
left=20 mm,
top=20 mm,
}
\usepackage{bm, amssymb}
\usepackage{soul}
\usepackage{indentfirst}
\usepackage{palatino}
\usepackage[dvipsnames]{xcolor}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{enumitem}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{arydshln}
\usepackage{calc}
\usepackage{tasks, booktabs}
\setlength{\parindent}{2em}
\newcommand{\wt}[2]{\underset{\substack{\textstyle\uparrow\\\hidewidth\mathstrut#2\hidewidth}}{#1}}
\definecolor{mygray}{gray}{0.6}
\begin{document}
\textbf{Solution :} \\[0.5 cm]
\hspace*{0.5 cm}
\setlength\arraycolsep{0.2em}
\setlength{\tabcolsep}{2em}
{\centering
\begin{tabular}{@{}c | c | c@{}}
(a) 9's complement : &
(b) 7's complement : &
(c) 15's complement :\\[0.25 cm]
$\begin{matrix} & 9 & 9 & 9 & 9 \\ - & 5 & 8 & 4 & 2 \\ \cline{2-5} & 4 & 1 & 5 & 7 \end{matrix}$ &
$\begin{matrix} & 7 & 7 & 7 & 7 \\ - & 6 & 4 & 2 & 3 \\ \cline{2-5} & 1 & 3 & 5 & 4 \end{matrix}$ &
$\begin{matrix} & \mathrm{F} & \mathrm{F} & \mathrm{F} & \mathrm{F} \\ - & \mathrm{A} & 9 & 6 & \mathrm{D} \\ \cline{2-5} & 5 & 6 & 9 & 2 \end{matrix}$
\end{tabular}
}%
\vskip 1cm
\begin{tasks}[label=(\alph*),label-width=1.3em] (3)
\task 9's complement :
$\begin{matrix} & 9 & 9 & 9 & 9 \\ - & 5 & 8 & 4 & 2 \\ \cmidrule{2-5} & 4 & 1 & 5 & 7 \end{matrix}$
%%
\task 7's complement :
$\begin{matrix} & 7 & 7 & 7 & 7 \\ - & 6 & 4 & 2 & 3 \\ \cmidrule{2-5} & 1 & 3 & 5 & 4 \end{matrix}$
%%
\task 15's complement :
$\begin{matrix} & \mathrm{F} & \mathrm{F} & \mathrm{F} & \mathrm{F} \\ - & \mathrm{A} & 9 & 6 & \mathrm{D} \\ \cmidrule{2-5} & 5 & 6 & 9 & 2 \end{matrix}$
\end{tasks}
\end{document}