0

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:

enter image description here

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}
7
  • Are you ing two-column mode? We would need a complete, xompilable code that we can test. – Bernard Feb 22 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 at 22:53
  • <That was not my question. I meant – is the document class in two column mode? What is your layout? – Bernard Feb 22 at 22:55
  • 1
    longtable does not have an [H] option and should never be in center – David Carlisle Feb 22 at 23:21
  • 1
    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) – David Carlisle Feb 22 at 23:31
1

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.

enter image description here

\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
  • Thanks! I tried shortening the top headings. See my edit. – OGC Feb 23 at 0:09
  • 1
    @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. – David Carlisle Feb 23 at 0:17
1

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} 

enter image description here

3
  • hey you made the page wider:-) – David Carlisle Feb 23 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. – Bernard Feb 23 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" :-) – David Carlisle Feb 23 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.