1

I'm trying to fit my table on the page like this:

enter image description here

But instead it goes like this:

enter image description here

With the left side being the end of the page. How do I do this? This is what I have:

\begin{table}[!htb]
\centering

\begin{tabular}{|l|l|l|l|l|l|l|}
\hline
Monday-saturday & Full-time new (break after 3 hours) & Full-time new (break after 4 hours) & Part-time new & Total employees working & Minimum employees needed & Additional costs
\\\hline
10:00-11:00 & 0 & 1 & 1 & 2 & 2 & \euro0
\\\hline
11:00-12:00 & 1 & 0 & 2 & 5 & 5 & \euro 30
\\\hline
12:00-13:00 & 1 & 2 & 1 & 9 & 9 & \euro40
\\\hline
13:00-14:00 & 0 & 0 & 0 & 9 & 9 & \euro0
\\\hline
14:00-15:00 & 0 & 0 & 0 & 6 * 6 & \euro0
\\\hline
15:00-16:00 & 0 & 0 & 0 & 5 & 5 & \euro10
\\\hline
16:00-17:00 & 0 & 0 & 2 & 5 & 5 & \euro10 
\\\hline
17:00-18:00 & 0 & 0 & 4 & 11 & 9 & \euro0
\\\hline
18:00-19:00 & 0 & 0 & 0 & 10 & 10 & \euro10
\\\hline
19:00-20:00 & 0 & 0 & 0 & 9 & 9 & \euro40
\\\hline 
20:00-21:00 & 0 & 0 & 0 & 4 & 4 & \euro10
\\\hline

\end{tabular}   


\end{table}
2

Use a different column type. In the following example I switched one l to p{3cm} to break the column after 3cm.

But please next time provide a complete example including the preamble with any required packages. I had to define the \euro command myself since you did not specify the package you used.

\documentclass[12pt]{article}

\newcommand{\euro}{EUR~}
\begin{document}

\begin{table}[!htb]
\centering

\begin{tabular}{|l|p{3cm}|l|l|l|l|l|}
\hline
Monday-saturday & Full-time new (break after 3 hours) & Full-time new (break after 4 hours) & Part-time new & Total employees working & Minimum employees needed & Additional costs
\\\hline
10:00-11:00 & 0 & 1 & 1 & 2 & 2 & \euro0
\\\hline
11:00-12:00 & 1 & 0 & 2 & 5 & 5 & \euro 30
\\\hline
12:00-13:00 & 1 & 2 & 1 & 9 & 9 & \euro40
\\\hline
13:00-14:00 & 0 & 0 & 0 & 9 & 9 & \euro0
\\\hline
14:00-15:00 & 0 & 0 & 0 & 6 * 6 & \euro0
\\\hline
15:00-16:00 & 0 & 0 & 0 & 5 & 5 & \euro10
\\\hline
16:00-17:00 & 0 & 0 & 2 & 5 & 5 & \euro10 
\\\hline
17:00-18:00 & 0 & 0 & 4 & 11 & 9 & \euro0
\\\hline
18:00-19:00 & 0 & 0 & 0 & 10 & 10 & \euro10
\\\hline
19:00-20:00 & 0 & 0 & 0 & 9 & 9 & \euro40
\\\hline 
20:00-21:00 & 0 & 0 & 0 & 4 & 4 & \euro10
\\\hline

\end{tabular}   


\end{table}

\end{document}

result

  • Thanks! Yes, I'm sorry, I'll include the preamble next time. – Pim Dec 4 '14 at 19:41
  • @Mico: Sorry, I mistyped and forgot to check. I'll correct that. – Bernard Dec 4 '14 at 21:51
  • @Uwe Ziegenhagen: You should change p{3cm} to >{\raggedright}p{3cm}, loading the array package. – Bernard Dec 4 '14 at 21:52
  • Better still, load both the array and ragged2e packages and use >{\RaggedRight}p{3cm}. This will maintain hyphenation possiblities (which \raggedright does not). – Mico Dec 4 '14 at 22:43
2

I suggest you do the following:

  • Use a tabularx environment instead of tabular, and use a modified form of the X column type for columns 2 through 7. Like the basic p column type, the X column type lets material wrap across lines. Compared with the p column type, the X column type does all the required column width calculations for you. (The default is that all columns of type X have the same width; however, that can be changed.) The modification, illustrated in the code below, lets the material in the narrow columns be typeset in ragged-right mode instead of fully-justified mode.

  • To achieve an open-and-accessible look, get rid of all vertical lines and most interior horizontal lines. Use the macros of the booktabs package for the remaining three horizontal lines. You may want to insert a bit of whitespace after every third or fourth row.

  • If you want to enable hyphenation of the first words in each cell, use LuaLaTeX instead of pdfLaTeX. That, or insert \hspace{0pt} before "Minimum" and "Additional".

enter image description here

\documentclass{article}
\usepackage{eurosym}
\usepackage{tabularx,ragged2e,booktabs}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
\newenvironment{narrowtab}{\begin{tabular}[t]{@{}l@{}}}{\end{tabular}}

\begin{document}
\begin{table}[!htb]
\begin{tabularx}{\textwidth}{@{} l *{6}{Y} @{}}
\toprule
\begin{narrowtab}Monday--\\Saturday\end{narrowtab} & 
Full-time new (break after 3 hours) & 
Full-time new (break after 4 hours) & 
Part-time new & 
Total employees working & 
Minimum employees needed & 
Additional costs
\\
\midrule
10:00--11:00 & 0 & 1 & 1 & 2 & 2 & \euro0\\
11:00--12:00 & 1 & 0 & 2 & 5 & 5 & \euro 30\\
12:00--13:00 & 1 & 2 & 1 & 9 & 9 & \euro40\\
\addlinespace
13:00--14:00 & 0 & 0 & 0 & 9 & 9 & \euro0\\
14:00--15:00 & 0 & 0 & 0 & 6 & 6 & \euro0\\
15:00--16:00 & 0 & 0 & 0 & 5 & 5 & \euro10\\
\addlinespace
16:00--17:00 & 0 & 0 & 2 & 5 & 5 & \euro10 \\
17:00--18:00 & 0 & 0 & 4 & 11 & 9 & \euro0\\
18:00--19:00 & 0 & 0 & 0 & 10 & 10 & \euro10\\
\addlinespace
19:00--20:00 & 0 & 0 & 0 & 9 & 9 & \euro40\\ 
20:00--21:00 & 0 & 0 & 0 & 4 & 4 & \euro10\\
\bottomrule
\end{tabularx}   
\end{table}
\end{document}
0

I propose another approach with rotated table heads, a smaller font size and numbers right-aligned between them while left aligned in their column. I also use the booktabs package:

\documentclass[12pt,]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{array, makecell, tabularx, rotating, booktabs}
\usepackage{marvosym}
\newcommand{\euro}[1]{\EUR\,#1}
\renewcommand{\tabularxcolumn}[1]{>{\raggedright\small\arraybackslash}m{#1}}
\renewcommand\theadfont{\footnotesize}
\renewcommand\theadalign{lc}

\usepackage{siunitx}
\sisetup{table-format = 2.0,table-number-alignment = left}

\newcommand\till{$ \mkern2mu $--}

\begin{document}

\begin{table}[!htb]
\centering
\settowidth{\rotheadsize}{Minimum employees}
\renewcommand\cellrotangle{30}
\setlength\extrarowheight{2pt}
\footnotesize
\begin{tabularx}{\linewidth}{l@{\hskip-2em}*{3}{X}@{}*{3}{S@{\hskip-5.5em}}}
\rothead{\\\ Monday--Saturday} & \rothead{Full-time new\\\scriptsize (break after 3 hours)} & \rothead{Full-time new \\\scriptsize(break after 4 hours)} & \rothead{Part-time new} & {\rothead{Total employees \\working}} & {\rothead{Minimum employees\\ needed}} & {\rothead{Additional costs\\ (\EUR)}}
\\
\toprule
10:00\till 11:00 & 0 & 1 & 1 & 2 & 2 & 0\\
11:00\till 12:00 & 1 & 0 & 2 & 5 & 5 & 30 \\
12:00\till 13:00 & 1 & 2 & 1 & 9 & 9 & 40 \\
13:00\till 14:00 & 0 & 0 & 0 & 9 & 9 & 0 \\
14:00\till 15:00 & 0 & 0 & 0 & 6 & 6 & 0\\
15:00\till 16:00 & 0 & 0 & 0 & 5 & 5 & 10\\
16:00\till 17:00 & 0 & 0 & 2 & 5 & 5 & 10 \\
17:00\till 18:00 & 0 & 0 & 4 & 11 & 9 & 0 \\
18:00\till 19:00 & 0 & 0 & 0 & 10 & 10 & 10 \\
19:00\till 20:00 & 0 & 0 & 0 & 9 & 9 & 40 \\
20:00\till 21:00 & 0 & 0 & 0 & 4 & 4 & 10 \\
\bottomrule
\end{tabularx}
\end{table}

\end{document} 

enter image description here

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.