1

new to latex here. I am trying to align two tables at the same level next to each other, but adding more columns in the second table pushed it below the first.

\documentclass{article}
\begin{document}

\begin{tabular}{|c c c|} 
\hline
\multicolumn{3}{|c|}{Supervised} \\
\hline
XGBoost & LR & RF \\ [0.5ex] 
\hline\hline
0.76 & 0.45 & 0.83  \\  [0.5ex] 
\hline
\end{tabular}

\begin{tabular}{|c c c c c c c|} 
\hline
\multicolumn{7}{|c|}{Unsupervised} \\
\hline
LOF & ABOD & KNN & OCSVM & CBLOF & PCA & IF \\ [0.5ex] 
\hline\hline
0.11 & 0.07 & 0.03 & 0.01 & 0.01 & 0.01 & 0.01 \\  [0.5ex] 
\hline
\end{tabular}

\end{document}

enter image description here

Is there a way to align/center them both together without changing the margin?

7
  • 1
    Why are you enclosing each tabular in a one-inch-wide minipage?
    – Miyase
    Nov 23, 2022 at 19:38
  • I actually have no idea what it does, I edited my columns based on existing templates
    – No_Name
    Nov 23, 2022 at 19:41
  • It's very likely a bad idea with unwanted side-effects. Remove the minipage environments and see how it goes.
    – Miyase
    Nov 23, 2022 at 19:42
  • 1
    also if you want someone to debug your code it helps to provide it in form that my be used, so complete document. But remove the minipage (as presumably your tables are wider than 1in you must get warnings about them,then use \begin{tabular}[t] so the tables align on their top row. Nov 23, 2022 at 19:53
  • I have edited the code to complete it for reuse. Removing minipage and adding \begin{tabular}[t] did not make any difference.
    – No_Name
    Nov 23, 2022 at 20:04

2 Answers 2

0

enter image description here

\documentclass{article}
\begin{document}


\begin{center}\small
\setlength\tabcolsep{2pt}
\begin{tabular}[t]{@{}|c c c|@{}} 
\hline
\multicolumn{3}{@{}|c|@{}}{Supervised} \\
\hline
XGBoost & LR & RF \\ [0.5ex] 
\hline\hline
0.76 & 0.45 & 0.83  \\  [0.5ex] 
\hline
\end{tabular}~%
\begin{tabular}[t]{@{}|c c c c c c c|@{}} 
\hline
\multicolumn{7}{@{}|c|@{}}{Unsupervised} \\
\hline
LOF & ABOD & KNN & OCSVM & CBLOF & PCA & IF \\ [0.5ex] 
\hline\hline
0.11 & 0.07 & 0.03 & 0.01 & 0.01 & 0.01 & 0.01 \\  [0.5ex] 
\hline
\end{tabular}
\end{center}

\end{document}
1
  • This worked out! Thanks a ton.
    – No_Name
    Nov 23, 2022 at 20:18
0

May I suggest a booktabs visual? That's what the following code does. Additionally, like David's answer, you can just paste the two tables side-by-side by removing the blank line between them, or put everything in a single table.

enter image description here

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{center}
  \setlength{\tabcolsep}{0.5\tabcolsep}% To make the tables fit within the text block (50% or original value)
  \begin{tabular}{ c c c }
    \toprule
    \multicolumn{3}{ c }{Supervised} \\
    \cmidrule(lr){1-3}
    XGBoost & LR & RF \\
    \midrule
    0.76 & 0.45 & 0.83 \\
    \bottomrule
  \end{tabular}%
  \begin{tabular}{ *{7}{c} } 
    \toprule
    \multicolumn{7}{ c }{Unsupervised} \\
    \cmidrule(lr){1-7}
    LOF & ABOD & KNN & OCSVM & CBLOF & PCA & IF \\
    \midrule
    0.11 & 0.07 & 0.03 & 0.01 & 0.01 & 0.01 & 0.01 \\
    \bottomrule
  \end{tabular}
\end{center}

\bigskip

\begin{center}
  \setlength{\tabcolsep}{0.5\tabcolsep}% To make the tables fit within the text block (50% or original value)
  \begin{tabular}{ *{10}{c} }
    \toprule
    \multicolumn{3}{ c }{Supervised}
      & \multicolumn{7}{ c }{Unsupervised} \\
    \cmidrule(lr){1-3}\cmidrule(lr){4-10}
    XGBoost & LR & RF
      &  LOF & ABOD & KNN & OCSVM & CBLOF & PCA & IF \\
    \midrule
    0.76 & 0.45 & 0.83
      & 0.11 & 0.07 & 0.03 & 0.01 & 0.01 & 0.01 & 0.01 \\
    \bottomrule
  \end{tabular}
\end{center}

\end{document}
1
  • Thanks for this! Does seem way better to look at if both tables were combined.
    – No_Name
    Nov 24, 2022 at 20:17

You must log in to answer this question.

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