如何使这个表看起来更紧凑、更美观?

如何使这个表看起来更紧凑、更美观?
%\documentclass{article}

%\usepackage{longtable}

%\title{A longtable example}

%\begin{document}

%\begin{center}


\begin{table}[h!]
    \caption{WITS and ASUS Type of Treatment by Offender Type}
    \label{ASUS-WITS_treatment_table} 
    \centering
\begin{tabular}{l|l|l|l|l|l|l|}
    \cline{2-7}
    & \multicolumn{3}{c|}{WITS} & \multicolumn{3}{c|}{ASUS} \\ \hline
    \multicolumn{1}{|l|}{Treatment\textbackslash{}Offender Type} &
    Probationer &
    Parolees &
    \begin{tabular}[c]{@{}l@{}}Maximum-term\\ Released Prisoners\end{tabular} &
    Probationers &
    Parolees &
    \begin{tabular}[c]{@{}l@{}}Maximum-term\\ Released Prisoners\end{tabular} \\ \hline
    \multicolumn{1}{|l|}{Outpatient}              &         &        &        &         &        &        \\ \hline
    \multicolumn{1}{|l|}{Intensive Outpatient}    &         &        &        &         &        &        \\ \hline
    \multicolumn{1}{|l|}{Day Treatment}           &         &        &        &         &        &        \\ \hline
    \multicolumn{1}{|l|}{Partial Hospitalization} &         &        &        &         &        &        \\ \hline
    \multicolumn{1}{|l|}{Short Term Residential}  &         &        &        &         &        &        \\ \hline
    \multicolumn{1}{|l|}{Inpatient}               &         &        &        &         &        &        \\ \hline
    \multicolumn{1}{|l|}{Long Term Residential}   &         &        &        &         &        &        \\ \hline
    \multicolumn{1}{|l|}{Therapuetic Community}   &         &        &        &         &        &        \\ \hline
\end{tabular}
\end{table}
%\end{center}

%\end{document}

上面的代码给出了下表:在此处输入图片描述

我想知道如何才能使表格更居中并且看起来更紧凑。

答案1

在此处输入图片描述

\documentclass{article}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{makecell}

\begin{document}

\begin{table}[h!]
    \caption{WITS and ASUS Type of Treatment by Offender Type}
    \label{ASUS-WITS_treatment_table} 
    \centering
\setlength{\tabcolsep}{4pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lllllll}
   \toprule
    & \multicolumn{3}{c}{WITS} & \multicolumn{3}{c}{ASUS} \\ 
    \cmidrule(r){2-4} \cmidrule(l){5-7}
    \thead{Treatment\textbackslash{}\\Offender Type} &
    \thead{Prob.} &
    \thead{Parol.} &
    \thead{Max.-term\\ Rel. Pris.} &
    \thead{Prob.} &
    \thead{Parol.} &
    \thead{Max.-term\\ Rel. Pris.}\\ 
    \midrule
    Outpatient              &         &        &        &         &        &        \\ 
    Intensive Outpatient    &         &        &        &         &        &        \\ 
    Day Treatment           &         &        &        &         &        &        \\  
    Partial Hospitalization &         &        &        &         &        &        \\
    \addlinespace 
    Short Term Residential  &         &        &        &         &        &        \\ 
    Inpatient               &         &        &        &         &        &        \\ 
    Long Term Residential   &         &        &        &         &        &        \\ 
    Therapuetic Community   &         &        &        &         &        &        \\ \bottomrule
    \multicolumn{7}{@{}p{\textwidth}@{}}{Prob. = Probationer; Parol. = Parolees; Max.-term Rel. Pris. = Maximum-term Released Prisoners}\\
\end{tabular*}

\end{table}
 
\end{document}

答案2

在此处输入图片描述

\documentclass[10pt,a4paper]{article}
\usepackage{booktabs, makecell}
%\usepackage[T1]{fontenc}
\begin{document}
    \begin{table}[h!]
        \caption{WITS and ASUS Type of Treatment by Offender Type}
        \label{ASUS-WITS_treatment_table} 
        \centering
        \noindent\hspace{-3cm}
    \begin{tabular}{lllllll}
        \toprule
        & \multicolumn{3}{c}{WITS} & \multicolumn{3}{c}{ASUS} \\ \cmidrule(lr){2-4} \cmidrule(lr){5-7}
        \multicolumn{1}{l}{\makecell[l]{Treatment\\ \textbackslash{}Offender Type}} &
        Probationer &
        Parolees &
        \begin{tabular}[c]{@{}l@{}}Maximum-term\\ Released Prisoners\end{tabular} &
        Probationers &
        Parolees &
        \begin{tabular}[c]{@{}l@{}}Maximum-term\\ Released Prisoners\end{tabular} \\ \midrule
        \multicolumn{1}{l}{Outpatient}              &         &        &        &         &        &        \\ \midrule
        \multicolumn{1}{l}{Intensive Outpatient}    &         &        &        &         &        &        \\ \midrule
        \multicolumn{1}{l}{Day Treatment}           &         &        &        &         &        &        \\ \midrule
        \multicolumn{1}{l}{Partial Hospitalization} &         &        &        &         &        &        \\ \midrule
        \multicolumn{1}{l}{Short Term Residential}  &         &        &        &         &        &        \\ \midrule
        \multicolumn{1}{l}{Inpatient}               &         &        &        &         &        &        \\ \midrule
        \multicolumn{1}{l}{Long Term Residential}   &         &        &        &         &        &        \\ \midrule
        \multicolumn{1}{l}{Therapuetic Community}   &         &        &        &         &        &        \\ \bottomrule
    \end{tabular}
\end{table}

\end{document}

答案3

你说的更紧凑是什么意思?调整到页面 ->adjustbox 另外,我会将标题与表格右对齐,在我看来,表格看起来更好,没有太多的线条,尤其是垂直的

\documentclass{article}

\usepackage{longtable}
\title{A longtable example}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup{justification=raggedright,singlelinecheck=false}
\usepackage{arydshln}
\usepackage{adjustbox}

\begin{document}

\begin{table}[h!]
    \caption{WITS and ASUS Type of Treatment by Offender Type}
    \label{ASUS-WITS_treatment_table} 
    \centering
    \begin{adjustbox}{width=1\textwidth}
        \renewcommand{\arraystretch}{1.2}
\begin{tabular}{llll:lll}
   
    & \multicolumn{3}{c}{WITS} & \multicolumn{3}{c}{ASUS} \\ \hline
    \multicolumn{1}{l}{Treatment\textbackslash{}Offender Type} &
    Probationer &
    Parolees &
    \begin{tabular}[c]{@{}l@{}}Maximum-term\\ Released Prisoners\end{tabular} &
    Probationers &
    Parolees &
    \begin{tabular}[c]{@{}l@{}}Maximum-term\\ Released Prisoners\end{tabular} \\ \hline
    \multicolumn{1}{l}{Outpatient}              &         &        &        &         &        &        \\ 
    \multicolumn{1}{l}{Intensive Outpatient}    &         &        &        &         &        &        \\ 
    \multicolumn{1}{l}{Day Treatment}           &         &        &        &         &        &        \\  
    \multicolumn{1}{l}{Partial Hospitalization} &         &        &        &         &        &        \\ 
    \multicolumn{1}{l}{Short Term Residential}  &         &        &        &         &        &        \\ 
    \multicolumn{1}{l}{Inpatient}               &         &        &        &         &        &        \\ 
    \multicolumn{1}{l}{Long Term Residential}   &         &        &        &         &        &        \\ 
    \multicolumn{1}{l}{Therapuetic Community}   &         &        &        &         &        &        \\ \hline
\end{tabular}
\end{adjustbox}
\end{table}

\end{document}

在此处输入图片描述

相关内容