2

I'm transferring some latex code form sharelatex to texworks, and although this code works perfectly in sharelatex, it seems to be hiccuping on the three parttable in texworks. Any idea what I'm doing wrong?

Thanks!

\documentclass[portrait 12pt]{article}
\usepackage[left=1in,top=1in,right=1in,bottom=1in,nohead,nofoot]{geometry}
\usepackage{booktabs}
\usepackage{lscape}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage[normalem]{ulem}
\usepackage{rotating}
\usepackage{threeparttable}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{hyperref}
\usepackage{float}
\usepackage{adjustbox}
\usepackage[utf8]{inputenc}
\usepackage{verbatim}
\usepackage{color}
\usepackage{caption}
\usepackage{amsmath}

\setlength{\parskip}{.25cm}
\setlength\parindent{0pt}

\setcounter{tocdepth}{1}

\newcommand{\sym}[1]{{#1}}
\title{Tablet Data Report}
\author{Cory}
\date{}

\def \OutputPath {"C:/Users/ifmr/Dropbox/Education v2/Clean Data Pipes, 2018/Analysis/launcher/Output/"}

\begin{document}
\maketitle

\section{Summary Statistics}

\begin{table}[H]
    \caption{Cumulative Session Length (Hours)}
    \label{}
    \begin{center}
        \resizebox{300pt}{!}{
            \begin{threeparttable}
                \begin{tabular}{4*{6}c}
                    \input{\OutputPath Tables/cumulative_length}
                \end{tabular}
                \begin{tablenotes}
                \end{tablenotes}
            \end{threeparttable}
        }
    \end{center}
\end{table}


\begin{figure}[H]
    \centering
    \includegraphics[width=0.6\linewidth]{\OutputPath Graphs/weekly_duration}
        \caption{Average Session Length By Week}
\end{figure}

\end{document}

The actual code for the table is below:

 & \multicolumn{6}{c}{\textbf{Class}} \\
\textbf{School}&\textbf{1}&\textbf{2}&\textbf{3}&\textbf{4}&\textbf{5}&\textbf{Total} \\
\midrule
Asharfabad&2.13&1.87&2.28&2.95&2.56&11.78 \\
RN3&0.24&0.00&0.00&0.00&0.63&0.86 \\
Seiko&0.00&0.00&0.00&0.00&0.75&0.75 \\
2
  • I think there's something wrong in your column definition\begin{tabular}{4*{6}c}. How many are your actual columns?
    – CarLaTeX
    Commented Aug 10, 2018 at 4:49
  • Ahh sorry, I just updated my question to include table for the code. I"m not very good at latex so I don't know if row headers count as a column, but I'm pretty sure there are six columns
    – Cory
    Commented Aug 10, 2018 at 6:02

1 Answer 1

2

If you want to put a note without a \item use para option in the tablenotes environment.

Moreover:

  1. Look at When should we use \begin{center} instead of \centering?
  2. avoid using resizebox to resize a table, it is better to use the appropriate font, for example \large (but in this case the normalsize caption is awful, in my opinion, I wouldn't change the font at all).
  3. since you loaded dcolumn, use it for better number alignment.

I have also loaded array to add some space between rows modifying \arraystretch.

\documentclass[portrait 12pt]{article}
\usepackage[left=1in,top=1in,right=1in,bottom=1in,nohead,nofoot]{geometry}
\usepackage{array}
\renewcommand{\arraystretch}{1.2}
\usepackage{booktabs}
\usepackage{lscape}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage{dcolumn}
 \newcolumntype{d}[1]{D{.}{.}{#1}}
\usepackage[normalem]{ulem}
\usepackage{rotating}
\usepackage{threeparttable}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{hyperref}
\usepackage{float}
\usepackage{adjustbox}
\usepackage[utf8]{inputenc}
\usepackage{verbatim}
\usepackage{color}
\usepackage{caption}
\usepackage{amsmath}

\setlength{\parskip}{.25cm}
\setlength\parindent{0pt}

\setcounter{tocdepth}{1}

\newcommand{\sym}[1]{{#1}}
\title{Tablet Data Report}
\author{Cory}
\date{}

\def \OutputPath {"C:/Users/ifmr/Dropbox/Education v2/Clean Data Pipes, 2018/Analysis/launcher/Output/"}

\begin{document}
    \maketitle

    \section{Summary Statistics}

    \begin{table}[H]\centering\large
        \caption{Cumulative Session Length (Hours)\label{alabel}}
        \begin{threeparttable}
            \begin{tabular}{l*{5}{d{1.2}}d{2.2}}
                & \multicolumn{5}{c}{\textbf{Class}} \\
                \cmidrule(lr){2-6}
                \textbf{School}&\multicolumn{1}{c}{\textbf{1}}&\multicolumn{1}{c}{\textbf{2}}&\multicolumn{1}{c}{\textbf{3}}&\multicolumn{1}{c}{\textbf{4}}&\multicolumn{1}{c}{\textbf{5}}&\multicolumn{1}{c}{\textbf{Total}} \\
                \midrule
                Asharfabad&2.13&1.87&2.28&2.95&2.56&11.78 \\
                RN3&0.24&0.00&0.00&0.00&0.63&0.86 \\
                Seiko&0.00&0.00&0.00&0.00&0.75&0.75 \\
                \bottomrule
            \end{tabular}
        \begin{tablenotes}[para,flushleft]
            If your table doesn't have a note, why do you use threeparttable?
        \end{tablenotes}
        \end{threeparttable}
    \end{table}

    \begin{figure}[H]
        \centering
        \includegraphics[width=0.6\linewidth]{example-image-a}
        \caption{Average Session Length By Week}
    \end{figure}

\end{document}

enter image description here

Edit:

Since you can't change your input file, the best alignment, in my opition is r:

\begin{filecontents*}{cumulative_length.tex}
& \multicolumn{6}{c}{\textbf{Class}} \\
\textbf{School}&\textbf{1}&\textbf{2}&\textbf{3}&\textbf{4}&\textbf{5}&\textbf{Total} \\
\midrule
Asharfabad&2.13&1.87&2.28&2.95&2.56&11.78 \\
RN3&0.24&0.00&0.00&0.00&0.63&0.86 \\
Seiko&0.00&0.00&0.00&0.00&0.75&0.75 \\
\end{filecontents*}

\documentclass[portrait 12pt]{article} 
\usepackage[left=1in,top=1in,right=1in,bottom=1in,nohead,nofoot]{geometry} 
\usepackage{array} 
\renewcommand{\arraystretch}{1.2} 
\usepackage{booktabs} 
\usepackage{lscape} 
\usepackage{graphicx} 
\usepackage{caption} 
\usepackage{subcaption} 
\usepackage{booktabs} 
\usepackage{dcolumn} 
\newcolumntype{d}[1]{D{.}{.}{#1}} 
\usepackage[normalem]{ulem} 
\usepackage{rotating} 
\usepackage{threeparttable} 
\usepackage{multirow} 
\usepackage{multicol} 
\usepackage{hyperref} 
\usepackage{float} 
\usepackage{adjustbox} 
\usepackage[utf8]{inputenc} 
\usepackage{verbatim} 
\usepackage{color} 
\usepackage{caption} 
\usepackage{amsmath} 
\setlength{\parskip}{.25cm} 
\setlength\parindent{0pt} 
\setcounter{tocdepth}{1} 
\newcommand{\sym}[1]{{#1}} 
\title{Tablet Data Report} 
\author{Cory} 
\date{} 
\def \OutputPath {"C:/Users/ifmr/Dropbox/Education v2/Clean Data Pipes, 2018/Analysis/launcher/Output/"} 
\begin{document} 
\maketitle \section{Summary Statistics} 
\begin{table}[H]\centering\large 
\caption{Cumulative Session Length (Hours)\label{alabel}} 
\begin{threeparttable} 
\begin{tabular}{l*{6}{r}}
\toprule
 \input{cumulative_length}
\bottomrule 
\end{tabular} 
\begin{tablenotes}[para,flushleft] 
If your table doesn't have a note, why do you use threeparttable? 
\end{tablenotes} 
\end{threeparttable} 
\end{table} 
\begin{figure}[H]\centering 
\includegraphics[width=0.6\linewidth]{example-image-a} 
\caption{Average Session Length By Week}
\end{figure} 
\end{document}

enter image description here

4
  • Thanks so much for your help! I'm using the stata package tabout to output a table to latex form, so I'm sorta stuck with the actual table contents, but your advice on the code before and after has really helped!
    – Cory
    Commented Aug 11, 2018 at 5:12
  • @Cory Which is the part you can't change? What you posted as "the actual code for the table"?
    – CarLaTeX
    Commented Aug 11, 2018 at 5:27
  • Yes exactly. I use the tabout command with many different data so needed a way to work with its format. Thanks again for your help.
    – Cory
    Commented Aug 13, 2018 at 5:50
  • @Cory See my edit. The filecontents* environment at the beginning is only to create a cumulative_length.tex file, of course you don't need to use it because you already have the file :)
    – CarLaTeX
    Commented Aug 13, 2018 at 9:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .