使用我当前版本的代码,该表看起来有点不对。
\documentclass{article}
\usepackage{longtable}
\title{A longtable example}
\begin{document}
\begin{center}
\begin{longtable}[H]{|p{2.5cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|}
\caption{WITS and ASUS Type of Treatment by Offender Type}
\label{test_table} \\ \hline
&\multicolumn{3}{c|}{\textbf{WITS}}&\multicolumn{3}{c|}{\textbf{ASUS}}\\ \hline
\textbf{Treatment \textbackslash{} Offender Type} & \textbf{Probationer} & \textbf{Parolees} &\textbf{Maximum-term Released Prisoners} & \textbf{Probationer} & \textbf{Parolees} &\textbf{Maximum-term Released Prisoners} \\ \hline
Outpatient& & & & & & \\ \hline
Intensive Outpatient& & & & & &\\ \hline
Day Treatment& & & & & & \\ \hline
Partial Hospitalization& & & & & &\\ \hline
Short Term Residential& & & & & &\\ \hline
Inpatient& & & & & &\\ \hline
Long Term Residential& & & & & &\\ \hline
Therapeutic Community& & & & & &\\ \hline
\end{longtable}
\end{center}
\end{document}
请参阅此处了解输出:
有什么建议可以让我格式化它并使其更美观吗?我一直试图调整表格的宽度,但无济于事。
编辑:我尝试了这样的事情:
> %\documentclass{article}
> %\usepackage{longtable}
>
> %\title{A longtable example}
>
> %\begin{document}
>
> %\begin{center}
> \begin{longtable}[H]{|p{2.5cm}|p{1.2cm}|p{1.2cm}|p{1.5cm}|p{1.2cm}|p{1.2cm}|p{1.5cm}|}
> \caption{WITS and ASUS Type of Treatment by Offender Type}
> \label{ASUS-WITS_treatment_table2} \\ \hline
> &\multicolumn{3}{c|}{\textbf{WITS}}&\multicolumn{3}{c|}{\textbf{ASUS}}\\
> \hline \textbf{Treatment \textbackslash{} Offender Type} &
> \textbf{Prob.} & \textbf{Parol.} &\textbf{Max-term Rel. Pris.} &
> \textbf{Prob.} & \textbf{Parol.} &\textbf{Max-term Rel. Pris.} \\
> \hline Outpatient& & & & & & \\ \hline Intensive Outpatient& &
> & & & &\\ \hline Day Treatment& & & & & & \\ \hline Partial
> Hospitalization& & & & & &\\ \hline Short Term Residential& &
> & & & &\\ \hline Inpatient& & & & & &\\ \hline Long Term
> Residential& & & & & &\\ \hline Therapeutic Community& & & &
> & &\\ \hline \multicolumn{7}{@{}p{\textwidth}@{}}{Prob. =
> Probationer; Parol. = Parolees; Max.-term Rel. Pris. = Maximum-term
> Released Prisoners}\\ \end{longtable} %\end{center}
>
> %\end{document}
答案1
您已指定表格比页面更宽,因此我减小了列宽。
如果顶部标题较短的话看起来会更好,但是您需要学科知识才能选择更好的标题,因此我保留它们原样。
\documentclass{article}
\usepackage{longtable,array}
\title{A longtable example}
\begin{document}
\setlength\extrarowheight{2pt}
\begin{longtable}{|>{\raggedright}p{2.3cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|}
\caption{WITS and ASUS Type of Treatment by Offender Type}
\label{test_table} \\ \hline
&\multicolumn{3}{c|}{\textbf{WITS}}&\multicolumn{3}{c|}{\textbf{ASUS}}\\ \hline
\textbf{Treatment \textbackslash{} Offender Type} & \textbf{Prob\-ationer} & \textbf{Parol\-ees} &\textbf{Maxi\-mum term Released Prisoners} & \textbf{Prob\-ationer} & \textbf{Parol\-ees} &\textbf{Maxi\-mum term Released Prisoners} \\ \hline
Outpatient\\\mbox {}& & & & & & \\ \hline
Intensive Outpatient& & & & & &\\ \hline
Day Treatment& & & & & & \\ \hline
Partial Hospitalization& & & & & &\\ \hline
Short Term Residential& & & & & &\\ \hline
Inpatient\\\mbox{ }& & & & & &\\ \hline
Long Term Residential& & & & & &\\ \hline
Therapeutic Community& & & & & &\\ \hline
\end{longtable}
\noindent X\dotfill X
\end{document}
答案2
我建议使用结合了和xltabular
功能的环境。longtable
tabularx
此外,根据您表格的实际内容,您可以考虑使用横向表格。
\documentclass[11pt, letterpaper]{article}
\usepackage[margin=0.75in]{geometry}
\usepackage{caption}
\usepackage{longtable}
\usepackage{xltabular}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\usepackage{ragged2e}
\newcolumntype{Y}{>{\hsize=0.7\hsize\RaggedRight\arraybackslash}X}
\title{A longtable example}
\begin{document}
\setlength{\extrarowheight}{2pt}\setlength{\tabcolsep}{2pt}
\captionsetup{width=\linewidth}
\begin{xltabular}{\linewidth}{|>{\hsize=1.6\hsize\RaggedRight}X|*{2}{X|Y|X|}}
\caption{WITS and ASUS Type of Treatment by Offender Type}
\label{test_table} \\ \hline
&\multicolumn{3}{c|}{\textbf{WITS}}&\multicolumn{2}{c|}{\textbf{ASUS}}\\ \hline
\textbf{Treatment \textbackslash{}\newline Offender Type} & \textbf{Probationer} & \textbf{Parolees} &\textbf{Maximum-term Released Prisoners} & \textbf{Probationer} & \textbf{Parolees} &\textbf{Maximum-term Released Prisoners} \\ \hline
Outpatient& & & & & & \\ \hline
Intensive Outpatient& & & & & &\\ \hline
Day Treatment& & & & & & \\ \hline
Partial Hospitalization& & & & & &\\ \hline
Short Term Residential& & & & & &\\ \hline
Inpatient& & & & & &\\ \hline
Long Term Residential& & & & & &\\ \hline
Therapeutic Community& & & & & &\\ \hline
\end{xltabular}
\end{document}