简体   繁体   中英

align values in latex

i have a problem in LaTeX. I want the accuracy value centered in its cell since it is not associated with the labels but I don't know how to do it.

在此处输入图像描述

Here the code I'm using:

\documentclass[12 pt, letterpaper, twoside, openright]{book}
\usepackage{amsmath} 

\usepackage{multirow} 

\usepackage{enumitem}
\usepackage{booktabs, makecell, longtable}
\usepackage{stackengine}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}
\begin{table}[H]
\caption {Logistic Regression and Random Forest Performances}
\centering
 \begin{tabular}{llssssssss}
    \toprule
    \multirow{2}{*}{Patient} &\multirow{2}{*}{Labels} &
      \multicolumn{4}{c}{Logistic Regression} &
      \multicolumn{4}{c}{Random Forest} \\
      && {Accuracy (\%)}&{$Prec$} & {$Rec$} & {$F1$} & {Accuracy (\%)}& {$Prec$} & {$Prec$} & {$F1$} \\
      \midrule
\multirow{2}{3em}{F0110} & 0 & 55 & 0.59 & 0.62 & 0.61 & 55& 0.70 & 0.76 & 0.72 \\ 
 & 1 & & 0.58 & 0.55 & 0.57& & 0.72 & 0.66 & 0.69 \\
 \hline

 \bottomrule
  \end{tabular}
 \label{tab:tab1}
\end{table}

\end{document}

you can use the same \multirow command as with the "FO110" cell

\documentclass[12 pt, letterpaper, twoside, openright]{book}
\usepackage{amsmath} 

\usepackage{multirow} 

\usepackage{enumitem}
\usepackage{booktabs, makecell, longtable}
\usepackage{stackengine}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}
\begin{table}[ht]
\caption {Logistic Regression and Random Forest Performances}
\centering
 \begin{tabular}{llcccccccc}
    \toprule
    \multirow{2}{*}{Patient} &\multirow{2}{*}{Labels} &
      \multicolumn{4}{c}{Logistic Regression} &
      \multicolumn{4}{c}{Random Forest} \\
      && {Accuracy (\%)}&{$Prec$} & {$Rec$} & {$F1$} & {Accuracy (\%)}& {$Prec$} & {$Prec$} & {$F1$} \\
      \midrule
\multirow{2}{3em}{F0110} & 0 & \multirow{2}{1em}{55} & 0.59 & 0.62 & 0.61 & \multirow{2}{1em}{55}& 0.70 & 0.76 & 0.72 \\ 
 & 1 & & 0.58 & 0.55 & 0.57& & 0.72 & 0.66 & 0.69 \\
 \hline

 \bottomrule
  \end{tabular}
 \label{tab:tab1}
\end{table}

\end{document}

As said in your previous post, the tabularray packages makes merging cells much easier:

\documentclass[12 pt, letterpaper, twoside, openright]{book}

\usepackage{float}

\usepackage{tabularray}
 \UseTblrLibrary{booktabs}

\begin{document}
\begin{table}[H]
\caption{Logistic Regression and Random Forest Performances}
\centering
 \begin{tblr}{llcccccccc}
    \toprule
    \SetCell[r=2]{} Patient & 
    \SetCell[r=2]{} Labels &
    \SetCell[c=4]{} Logistic Regression &&&&
    \SetCell[c=4]{} Random Forest  &&& \\
      && {Accuracy (\%)}&{$Prec$} & {$Rec$} & {$F1$} & {Accuracy (\%)}& {$Prec$} & {$Prec$} & {$F1$} \\
      \midrule
\SetCell[r=2]{} F0110 & 0 & \SetCell[r=2]{}55 & 0.59 & 0.62 & 0.61 & \SetCell[r=2]{}55& 0.70 & 0.76 & 0.72 \\ 
 & 1 & & 0.58 & 0.55 & 0.57& & 0.72 & 0.66 & 0.69 \\
 \bottomrule
  \end{tblr}
 \label{tab:tab1}
\end{table}

\end{document}

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM