2

I am attempting to create a single table that appears to be two separate tables, side by side. Each "table" should have text below it explaining what the table relates to. The text below each "table" is causing the final column to expand (see picture).

I would like all columns to be an equal width, with the text being no longer than the width of each table, but I can't seem to figure out how to do it.

enter image description here

Below is the code that I am using.

\begin{table}[H]
\centering
\begin{adjustbox}{width=\textwidth}
\begin{tabular}{ccccccccc}
\cline{1-4} \cline{6-9}
\multicolumn{1}{|c|}{} &
  \multicolumn{1}{c|}{\textbf{A}} &
  \multicolumn{1}{c|}{\textbf{B}} &
  \multicolumn{1}{c|}{\textbf{C}} &
  \multicolumn{1}{c|}{\textbf{}} &
  \multicolumn{1}{c|}{} &
  \multicolumn{1}{c|}{\textbf{A}} &
  \multicolumn{1}{c|}{\textbf{B}} &
  \multicolumn{1}{c|}{\textbf{C}} \\ \cline{1-4} \cline{6-9} 
\multicolumn{1}{|c|}{\textbf{A}} &
  \multicolumn{1}{c|}{0} &
  \multicolumn{1}{c|}{0} &
  \multicolumn{1}{c|}{0} &
  \multicolumn{1}{c|}{} &
  \multicolumn{1}{c|}{\textbf{A}} &
  \multicolumn{1}{c|}{0} &
  \multicolumn{1}{c|}{0} &
  \multicolumn{1}{c|}{0} \\ \cline{1-4} \cline{6-9} 
\multicolumn{1}{|c|}{\textbf{B}} &
  \multicolumn{1}{c|}{1} &
  \multicolumn{1}{c|}{0} &
  \multicolumn{1}{c|}{0} &
  \multicolumn{1}{c|}{} &
  \multicolumn{1}{c|}{\textbf{B}} &
  \multicolumn{1}{c|}{1} &
  \multicolumn{1}{c|}{0} &
  \multicolumn{1}{c|}{0} \\ \cline{1-4} \cline{6-9} 
\multicolumn{1}{|c|}{\textbf{C}} &
  \multicolumn{1}{c|}{0} &
  \multicolumn{1}{c|}{1} &
  \multicolumn{1}{c|}{0} &
  \multicolumn{1}{c|}{} &
  \multicolumn{1}{c|}{\textbf{C}} &
  \multicolumn{1}{c|}{1} &
  \multicolumn{1}{c|}{1} &
  \multicolumn{1}{c|}{1} \\ \cline{1-4} \cline{6-9} 
\multicolumn{4}{l}{Transitive dependency} &
  \multicolumn{1}{l}{\textbf{}} &
  \multicolumn{4}{l}{Direct dependency}
\end{tabular}
\end{adjustbox}
\caption{Adjacency matrices}
\label{tab:adjacency_matrix}

\end{table}

2 Answers 2

3

Welcome to TeX.SE!

  • Please. always provide MWE (Minimal Working Example), a small but complete document, which begin with \documentclass and end{document}
  • In preamble MWE should load only to your problem relevant packages.

Something like this:

enter image description here

With use tblr table, defined by tabularray package, MWE is simple:

\documentclass{article}
\usepackage{tabularray}

\begin{document}
    \begin{table}[ht]
    \centering
\begin{tblr}{hline{1-Y} = {1-4,6-Z}{solid},
             vline{1-Z} = {1-Y}{solid}, %{solid},
             colspec = {X[c, font=\bfseries] *{4}{X[c]} 
                        X[c, font=\bfseries] *{3}{X[c]}},
             row{1}  = {font=\bfseries},
             row{Z}  = {font=\normalfont}
             }
    & A & B & C &   &   & A & B & C \\
A   & 0 & 0 & 0 &   & A & 0 & 0 & 0 \\
B   & 1 & 0 & 0 &   & B & 1 & 0 & 0 \\
C   & 0 & 1 & 0 &   & C & 1 & 1 & 1 \\ 
\SetCell[c=4]{c}    Transitive dependency
    &   &   &   &   &   \SetCell[c=4]{c}    Direct dependency
                        &   &   &   \\
\end{tblr}
\caption{Adjacency matrices}
\label{tab:adjacency_matrix}
    \end{table}
\end{document}
0
2

It seems to me that it makes sense to create two subtables rather than a single table split in two. This can be done with subtable from the subcaption package. Also, using p columns in the tabular environments, you can specify the width of the columns manually (then you are sure that they all have the same width).

\documentclass{article}
\usepackage{subcaption}
\usepackage{array}
\begin{document}
\begin{table}
\captionsetup[subtable]{labelformat=empty}
\begin{subtable}{.5\textwidth}
    \centering
    \begin{tabular}{|*{4}{>{\centering\arraybackslash}p{5mm}|}}
        \hline
        & \textbf{A} & \textbf{B} & \textbf{C} \\ \hline
        \textbf{A} & 0 & 0 & 0 \\ \hline
        \textbf{B} & 1 & 0 & 0 \\ \hline
        \textbf{C} & 0 & 1 & 0 \\ \hline
    \end{tabular}
    \caption{Transitive dependency}
\end{subtable}%
\begin{subtable}{.5\textwidth}
    \centering
    \begin{tabular}{|*{4}{>{\centering\arraybackslash}p{5mm}|}}
        \hline
        & \textbf{A} & \textbf{B} & \textbf{C} \\ \hline
        \textbf{A} & 0 & 0 & 0 \\ \hline
        \textbf{B} & 1 & 0 & 0 \\ \hline
        \textbf{C} & 1 & 1 & 1 \\ \hline
    \end{tabular}
    \caption{Direct dependency}
\end{subtable}
\caption{Adjacency matrices}
\end{table}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .