3

I created the following table, which showed up nicely in the document on its own:

    \begin{table}[!ht]
    \begin{tabular}{cccc}
    \caption{MyCaption}

    --data goes here--

    \end{tabular}
    \end{table}

However, after I integrated it within my document, it completely runs off the right side of the page. How do I get it to keep its size?

Edit: it's a very small table, 4 columns, so the size isn't the problem.

\documentclass[12pt]{report}
\usepackage{thesis}
\usepackage{apacite}
\usepackage{url}
\usepackage{graphicx}

\begin{document}
%\input{MyChapter}

\begin{table}[!ht]
\caption{Performance scores from assessments of divergent and convergent thinking tests of creativity and non-creativity (control task).}

\begin{tabular}{c{3cm}c{1cm}c{1cm}c{1cm}}
\hline
Variable & \textit{N} & \textit{M} & \textit{SD}\\
\hline
XYZ & \hfill & \hfill & \hfill\\
XXX & 17 & 222 & 2222\\
XXX & 22 & 111 & 11\\
XXX & 22 & 111 & 111\\
XXX & 22 & 111 & 111\\
XYZ & \hfill & \hfill & \hfill\\
XXX & 111 &  & 12\\
XXX & 111 & 2 & 1\\
\hline
\label{table:1}
\end{tabular}
\end{table}

\end{document}

I think it might be that the caption is too long. How do I get it to stay the same width as the table?

  • 3
    Welcome to the site :) In order to answer this question, I strongly suspect we will need to see just how you "integrated it within your document". And, in fact, the structure of the document is probably the important bit, could you provide a Minimal Working Example (MWE) – Au101 Aug 15 '16 at 21:41
  • your table is simple to wide to be fit in text or column width. to be able help you, I encourage you to consider @Au101 comment! – Zarko Aug 15 '16 at 21:43
  • does this help? sorry I'm still new to this so if you need more info please direct me to it \documentclass[12pt]{report} \usepackage{carletonthesis} \usepackage{apacite} \usepackage{url} \usepackage{graphicx} \input{MyChapters} \bibliography{MyBib} -the table is in one of the chapters- \end{document} – nahsn Aug 15 '16 at 21:50
  • And table? Problem is in it, doesn't it? – Zarko Aug 15 '16 at 22:21
  • You can highlight code in your post using back-ticks. For code-blocks indent them by four spaces or use the {} on the gui. – user30471 Aug 15 '16 at 22:31
3

I suspect that you looking something like this:

enter image description here

Above image of table is generated by:

\documentclass[12pt]{report}
\usepackage{threeparttable}
\usepackage{showframe}

\begin{document}

\begin{table}[htbp]
    \centering
\begin{threeparttable}
    \caption{Performance scores from assessments of divergent and convergent thinking tests of creativity and non-creativity (control task).}
\label{table:1}
    \begin{tabular}{p{3cm}p{1cm}p{1cm}p{1cm}}
    \hline
Variable    & \textit{N} & \textit{M} & \textit{SD}\\
    \hline
XYZ         &           &           &           \\
XXX         & 17        & 222       & 2222      \\
XXX         & 22        & 111       & 11        \\
XXX         & 22        & 111       & 111       \\
XXX         & 22        & 111       & 111       \\
XYZ         &           &           &           \\
XXX         & 111       &           & 12        \\
XXX         & 111       & 2         & 1         \\
    \hline
    \end{tabular}
\end{threeparttable}
\end{table}
\end{document}

In my MWE I use package showframe only for showing page layout. In real use it had to be removed.

To force caption to be the same width as table, I use package threeparttable. It enables to include caption in table. By this the caption is nod wider than table. Additionally, you can add to table list of (foot)notes, if you have them in table.

In my MWE I use p{...} column type instead unknown c. If you like to have centered cells contents, than you can define new column type, for examplec{...} as

\newcolumntype{c}[1]{>{\centering\arraybackslash}p{#1}}

I didn't figured out of purpose \hfill in many of your table cells, so I remove them.

| improve this answer | |

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.