Array all'interno di una tabella a 3 colonne

Sep 23 2020

Sto avendo una tabella con 3 colonne. All'interno di ogni colonna, sto cercando di utilizzare un array. Ma tutti gli array stanno arrivando nella prima colonna.

Codice:

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

Output ottenuto:

L'output ottenuto per il codice precedente è:

Uscita desiderata:

L'output desiderato è:

Qualcuno può aiutarmi a risolvere questo problema? Fornisci una soluzione standard che funzioni anche per diverse dimensioni di array.

Risposte

2 Bernard Sep 23 2020 at 21:15

L'array dovrebbe essere nella seconda riga della tabella. Tuttavia, suggerisco di utilizzare il taskspacchetto e il suo ambiente omonimo per una sintassi più naturale.

Non correlato : ho rimosso pacchetti già caricati da altri pacchetti (ad es. Amsfonts è caricato da amssymb, amsmath è caricato da mathtools). Notare che utf8 dovrebbe ora essere la codifica di input per impostazione predefinita. Usare l' matrixambiente al posto dell'array semplifica un po 'il codice. Inoltre, le regole da booktabshanno un certo riempimento verticale. Li ho usati nel codice con le attività.

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