[Tex/LaTex] Three horizontal subtables consisting of two vertical tables

tables

I want to make a table with three subtables horizontally aligned and each subtable consisting of two tables vertically aligned and text $x$-derivative and $y$-derivative which correspond to the two vertical tables. I have tried the subtable environment but my subtables goes in vertical direction and want them to go in the horizontal direction. Also I used a terrible solution to put in text in the table as a table itself without caption. Here is my working:

\documentclass{article}

\usepackage{subcaption}
\usepackage{color}

\begin{document}
\begin{table}
 \caption{First-order operator masks}
\centering

\begin{subtable}{0.5\linewidth}  
\begin{tabular}{cc}
$x$-derivative \\
\textcolor{white}{x}\\
\textcolor{white}{x}\\
$y$-derivative\\
\textcolor{white}{x}\\
\textcolor{white}{x}\\
\end{tabular}
\end{subtable}



\begin{subtable}{0.5\linewidth}
\caption{Roberts Operator}
        \label{tab:roberts}
\centering
\label{tab:robert}
\begin{tabular}{|c|c|}
\hline
0  & -1 \\ \hline
1 & 0  \\ \hline
\end{tabular}\\
\begin{tabular}{|c|c|}
\hline
-1 & 0 \\ \hline
0 & 1 \\ \hline
\end{tabular}
\vspace{0.5cm}

\end{subtable}%


\vspace{0.2cm}



 \begin{subtable}{0.5\linewidth}
    \caption{Prewitt operator}
\label{tab:prewitt}
       \begin{tabular}{|c|c|c|}
\hline
1 & 0 & -1 \\ \hline
1 & 0 & -1 \\ \hline
1 & 0 & -1 \\ \hline
\end{tabular}\\
\begin{tabular}{|c|c|c|}
\hline
1  & 1  & 1  \\ \hline
0  & 0  & 0  \\ \hline
-1 & -1 & -1 \\ \hline
\end{tabular}

\end{subtable}


\begin{subtable}{0.5\linewidth}
        \caption{Sobel operator}
        \label{tab:masks}
 \begin{tabular}{|c|c|c|}
\hline
1 & 0 & -1 \\ \hline
2 & 0 & -2 \\ \hline
1 & 0 & -1 \\ \hline
\end{tabular}
\\
\begin{tabular}{|c|c|c|}
\hline
1  & 2  & 1  \\ \hline
0  & 0  & 0  \\ \hline
-1 & -2 & -1 \\ \hline
\end{tabular}

\end{subtable}
\end{table}
\end{document}

Best Answer

I understand question slightly different than Piet van Oostrum ...

enter image description here

\documentclass{article}
\usepackage{subcaption}
\usepackage{array}
\newcolumntype{M}{>{$}c<{$}}
\newcommand\mcx[1]{\multicolumn{#1}{l}{$x$-derivative}}
\newcommand\mcy[1]{\multicolumn{#1}{l}{$y$-derivative}}

\begin{document}
    \begin{table}
\renewcommand\arraystretch{1.2}
\setlength\tabcolsep{11pt}

    \caption{First-order operator masks}
    \centering
\begin{subtable}[t]{0.25\linewidth}
\caption{Roberts Operator}
    \label{tab:roberts}
\centering
\label{tab:robert}
    \begin{tabular}{|M|M|}
\mcx{2}     \\   \hline
0   &   -1  \\  \hline
1   &   0   \\  \hline
\multicolumn{2}{c}{}    \\
\mcy{2}     \\  \hline
-1  & 0     \\  \hline
0   & 1     \\  \hline
    \end{tabular}
\end{subtable}%
    \hfil
\begin{subtable}[t]{0.37\linewidth}
    \caption{Prewitt operator}
\label{tab:prewitt}
\centering
    \begin{tabular}{|M|M|M|}
\mcx{3}             \\  \hline
1   &   0   &  -1   \\  \hline
1   &   0   &  -1   \\  \hline
1   &   0   &  -1   \\  \hline
\mcy{3}             \\      \hline
1   &   1   &   1   \\  \hline
0   &   0   &   0   \\  \hline
-1  &  -1   &  -1   \\  \hline
    \end{tabular}
\end{subtable}%
    \hfil
\begin{subtable}[t]{0.37\linewidth}
        \caption{Sobel operator}
\label{tab:masks}
\centering
\begin{tabular}{|M|M|M|}
\mcx{3}             \\  \hline
1   &   0   &  -1   \\  \hline
2   &   0   &  -2   \\  \hline
1   &   0   &  -1   \\  \hline
\mcy{3}             \\      \hline
1   &   2   &   1   \\  \hline
0   &   0   &   0   \\  \hline
-1  &  -2   &   -1  \\  \hline
    \end{tabular}
\end{subtable}
    \end{table}
\end{document}