# How to format this long table?

With the current version of my codes, the table looks a bit off.

    \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}


See here for the output:

Any suggestions how I can format it and make it more presentable? I have been trying adjusting the widths of the table but to no avail.

EDIT: I tried something like this:

> %\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}

• Are you ing two-column mode? We would need a complete, xompilable code that we can test. Feb 22, 2021 at 22:52
• @Bernard Yes, want to use the two main columns for WITS and ASUS, and have the three columns under each one of them. Does that make sense?
– OGC
Feb 22, 2021 at 22:53
• <That was not my question. I meant – is the document class in two column mode? What is your layout? Feb 22, 2021 at 22:55
• longtable does not have an [H] option and should never be in center Feb 22, 2021 at 23:21
• yes that was just a comment, neither affect the table, H does nothig at all and center has no affect on the table just introduces spurious vertical space (not visisble here as theer is nothing other than the table) Feb 22, 2021 at 23:31

You had specified the table to be wider than the page, so I reduced the column widths.

It would look better with shorter top headings, but you need subject knowledge to pick better headings so I left them as they are.

\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}

• Thanks! I tried shortening the top headings. See my edit.
– OGC
Feb 23, 2021 at 0:09
• @OGC your edit has the original bad column widths so will not fit the page, the intention was to use the version here, but just change the titles. But don't edit the answer into the question, it spils teh Q&A format of the site. Feb 23, 2021 at 0:17

I propose this, which uses the xltabular environment, which combines the functionalities of longtable and tabularx.

Also, depending on the real contents of your table, you might consider having a landscape table.

\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}


• hey you made the page wider:-) Feb 23, 2021 at 0:48
• @DavidCarlisle: In a comment, the O.P. said the margin was 0.75in with a letter paper format. He didn't seem quite sure, though. Feb 23, 2021 at 10:54
• No complaints really: I just was surprised that tabularx fitted that all in given how aggressively I'd had to line break the headers then I noticed that the "goalposts had moved" :-) Feb 23, 2021 at 16:01