0

I want to make my table fit in the text block. At the minute, a large part of my table is being cut off at the right-hand edge the page. My code is:

\documentclass{article}
\usepackage{graphicx} % for \scalebox macro
\begin{document}
\begin{table}[h]
        \begin{center}
            \scalebox{0.8}{
            \begin{tabular}{|l|l|l|l|l}
                \cline{1-4}
                Risk Event                          & Chance of Happening & Severity      & Measures to be taken                                                                                                        &  \\ \cline{1-4}
                Team member missing meetings        & Significant         & Low           & Encourage team members to read over minutes and inform of any tasks set. If regularly absent issue a warning and then card. &  \\ \cline{1-4}
                QA/Project manager missing meetings & Significant         & Low/Moderate  & Deputy in role will act as manager.                                                                                         &  \\ \cline{1-4}
                Team member leaving project group   & Low                 & Moderate/High & List all tasks assigned to missing team member and reassign them, after this refactor the timetable and planning.           &  \\ \cline{1-4}
            \end{tabular}}
        \end{center}
    \end{table}
\end{document}

I have tried replacing \begin{center} with flushleft to no avail. How can I make the table fit in the page?

lockstep
  • 250,273
Stormie
  • 397
  • Doesn't change anything I'm afraid. – Stormie Oct 22 '14 at 17:01
  • Besides all the other problems, you need to use \scalebox{0.8}{% to prevent an extra blank before the start of the \tabular. – John Kormylo Oct 22 '14 at 18:33
  • never use [h] on its own (latex usually warns and changes it to [ht] as it makes it virtually impossible to place the table). Normally you don't want \begin{center} in tables use \centering (as the table already adds vertical space so you do not want the extra space from center environment. Don't forget {% at ends of lines. don't scale tables (it produces font sizes inconsistent with the rest of the document). – David Carlisle Oct 22 '14 at 19:49
  • I used \begin{center} because I thought that \centering would leak through the rest of my document, is this not the case? – Stormie Oct 23 '14 at 01:14
  • 1
    @Stormie Try it, and see what happens. Spoiler alert: It's not the case. – Sverre Oct 23 '14 at 11:57
  • @Sverre When I change it from begin-end and use centering it changes the centering for the rest of my document. Is this a localized problem then? – Stormie Oct 23 '14 at 19:29
  • @Stormie That shouldn't happen, but it's hard to comment on that further without a minimal working example (MWE). – Sverre Oct 23 '14 at 19:31

3 Answers3

2

Your table has only four real columns; the fifth is always empty and should thus be omitted entirely. If you remove the fifth column, you can also replace all \cline{1-4} instructions with the simpler \hline.

The main problem with the table is, though, that it's much too wide for any normal page dimension unless you let the text in all four columns wrap. Hence, instead of the basic l column type, you should use a column type that lets the text wrap. I suggest you use the tabularx package and a (modified form of) that package's X column type. Set the width of the tabularx environment to \textwidth. Separately, because the columns are quite narrow, I suggest you typeset the material ragged-right rather than fully justified, in order to avoid very wide inter-word spaces.

enter image description here

\documentclass{article}
\usepackage{tabularx,ragged2e}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{|*{4}{Y|}}
   \hline
   Risk Event & Chance of Happening & Severity      & Measures to be taken \\
   \hline
   Team member missing meetings & Significant  & Low    & Encourage team members to read over minutes and inform of any tasks set. If regularly absent issue a warning and then card. \\ \hline
   QA/Project manager missing meetings & Significant  & Low/Moderate  & Deputy in role will act as manager.\\ \hline
   Team member leaving project group   & Low    & Moderate/High & List all tasks assigned to missing team member and reassign them, after this refactor the timetable and planning.  \\
   \hline
\end{tabularx}
\end{table} 
\end{document}

Addendum: Just for the sake of comparison, here's the original look of your table, where I've made only one adjustment to your code: I've used \resizebox{\textwidth}{!}{...} instead of \scalebox{0.8}{...} to make the table fit inside the text block. I think we can agree that using resizebox along with l-type columns is not the way to go in this case.

enter image description here

Mico
  • 506,678
  • This is fantastic, but it's also moved the table to a separate page outside of it's section.. Any idea why that's happened? – Stormie Oct 23 '14 at 01:31
  • @Stormie - The reformatted table is a lot taller than the original one and thus can no longer fit exactly in the previous location. Do you maybe set a location specifier such as \begin{table}[h]? If so, see what happens if you take away (or modify) the location specifier. LaTeX's float placement algorithm is a topic that goes far beyond the present question. For more information on this algorithm see, e.g., Frank Mittelbach's and Roelof Spijker's answers to How to influence the position of float environments like figure and table in LaTeX?. – Mico Oct 23 '14 at 05:27
1

You can do that with the tabularx package. To improve the tavle I also load cellspace , for a less tight vertical spacing of cell contents, and makecell for a common formatting of column heads and the possibility of line breaks in cells.

I didn't understand what the empty last column is here for, but if you don't use it, you might as well delete it. That would enable both to simplify the code and have the last vertical rule aligned with right margin.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[showframe, nomarginpar]{geometry}
\usepackage{array, tabularx}
\renewcommand{\tabularxcolumn}[1]{>{\raggedright}m{#1}}
\newcolumntype{Y}{ >{\hsize =0.8\hsize}X}
\newcolumntype{Z}{ >{\hsize =1.2\hsize}X}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadalign{lc}
\renewcommand\cellalign{lc}
\usepackage{cellspace}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\addparagraphcolumntypes{X, Y, Z}

\begin{document}

\begin{table}[!htbp]
        \begin{tabularx}{\linewidth}{|Y|l|l|S{Z}|l}
            \cline{1-4}
\thead{Risk Event} & \thead{Chance\\ of Happening} & \thead{Severity} & \thead{Measures\\ to be taken} & \\
\cline{1-4}
            Team member\break missing meetings & Significant & Low & Encourage team members to read over minutes and inform of any tasks set. If regularly absent issue a warning and then card. & \\
            \cline{1-4}
            QA/Project manager missing meetings & Significant & Low/Moderate & Deputy in role will act as manager. & \\
            \cline{1-4}
            Team member leaving project group & Low & Moderate/High & List all tasks assigned to missing team member and reassign them, after this refactor the timetable and planning. & \\
            \cline{1-4}
        \end{tabularx}%
\end{table}

\end{document} 

enter image description here

Bernard
  • 271,350
0

Use @{}:

\documentclass{article}
\usepackage[showframe]{geometry}
\begin{document}
\noindent\begin{tabular}{@{}*5{l}}
1 & 2 & 3 & 4 & 5\\
A & B & C & D & E\\
\end{tabular}
\end{document}

For future reference, please make your code compilable and minimal.


EDIT As John points out in his comment, you don't even need @{} if you have vertical lines in your table:

\documentclass{article}
\usepackage[showframe]{geometry}
\begin{document}
\noindent\begin{tabular}{*5{|l}}
1 & 2 & 3 & 4 & 5\\
A & B & C & D & E\\
\end{tabular}
\end{document}
Sverre
  • 20,729
  • 1
    Actually, with | you don't need @{} to remove the extra gap on side. – John Kormylo Oct 22 '14 at 18:35
  • In his case, he was getting an extra blank from the previous line. – John Kormylo Oct 22 '14 at 18:39
  • 1
    The OP's table has a lot of text material. You should mention the p column type as a method for making the material fit in the available text block. – Mico Oct 22 '14 at 19:28
  • @Mico The OP's question was how to left align a table. I didn't pay attention to the content of the cells since that doesn't play any role in the left alignment of the table. – Sverre Oct 22 '14 at 19:53
  • I think the OP was distracted by the fact that his/her table is so wide that it protrudes (massively!) into the right-hand margin. He/she may have thought that things were fixable by shifting the table a bit to the left. – Mico Oct 22 '14 at 19:57
  • @Mico I see. Then this question should possibly be closed as being unclear, since the question asked bears no relation to the problem at hand (if the problem is the bleeding into the right margin). This also means that no one with the same problem will find this question, given that it's called "How can I left align my table?". – Sverre Oct 22 '14 at 20:17
  • 2
    I think I'll go ahead and edit the posting's title and first few sentences, so that the description has a closer connection to the actual problem. – Mico Oct 22 '14 at 20:23