由两个垂直表组成的三个水平子表

由两个垂直表组成的三个水平子表

我想制作一个表格,其中三个子表格水平对齐,每个子表格由两个垂直对齐的表格和文本 $x$-derivative 和 $y$-derivative 组成,它们对应于两个垂直表格。我尝试了子表格环境,但我的子表格在垂直方向上移动,我希望它们在水平方向上移动。此外,我使用了一个糟糕的解决方案,将文本作为表格本身放入表格中,而没有标题。这是我的工作:

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

答案1

我理解的问题与皮特·范奥斯特鲁姆...

在此处输入图片描述

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

答案2

如果您希望子表格水平对齐(我猜这意味着在同一水平面上彼此相邻),那么不要在它们之间放置空行,因为这意味着开始一个新段落,因此是垂直放置。并且不要\vspace在它们之间放置。

另外,如果您希望子表格水平对齐,则它们的宽度不能为0.5\linewidth。这样一行就放不下。

话说回来,这是你想要的吗?

在此处输入图片描述

\documentclass{article}

\usepackage{subcaption}
\usepackage{color}

\begin{document}
\begin{table}
 \caption{First-order operator masks}
\begin{tabular}[t]{cc}
\\
\\
\\
$x$-derivative \\
\\
\\
$y$-derivative\\
\end{tabular}
%
\begin{subtable}[t]{0.25\textwidth}
\centering 
\caption{Roberts Operator}
        \label{tab:roberts}
\label{tab:robert}
\begin{tabular}{|c|c|}
\hline
0  & -1 \\ \hline
1 & 0  \\ \hline
\end{tabular}\\[\baselineskip]
\begin{tabular}{|c|c|}
\hline
-1 & 0 \\ \hline
0 & 1 \\ \hline
\end{tabular}
\end{subtable}%
 \begin{subtable}[t]{0.25\textwidth}
\centering 
    \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}
\quad
\begin{subtable}[t]{0.25\textwidth}
\centering 
        \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}

实际上,我认为如果您不使用子表,而是将所有小表放在一个有 4 列 3 行的大表格中,那么您将获得更漂亮的布局。第 1 行用于标题,第 2 行和第 3 行用于小表$x$-derivative$y$-derivative

相关内容