# table overflow page

I created a table with https://www.tablesgenerator.com/latex_tables

I tried to limit the column width with |l| p{1cm} |p{2cm} |p{1cm} |p{1cm} |p{2cm} |p{1cm} |p{1cm}| But it doesn't see to have any effect.

The generated table

\begin{table}[]
\begin{tabular}{llllllll}
\hline
\multicolumn{1}{|l|}{}                           & \multicolumn{1}{l|}{Compute}                                      & \multicolumn{1}{l|}{Pay As  You Go}                                  & \multicolumn{1}{l|}{}                                                & \multicolumn{1}{l|}{Storage}                                      & \multicolumn{1}{l|}{Pay As  You Go}                     & \multicolumn{1}{l|}{}                               & \multicolumn{1}{l|}{Trail}                          \\ \cline{2-3} \cline{5-6} \cline{8-8}
\multicolumn{1}{|l|}{\multirow{-2}{*}{Provider}} & \multicolumn{1}{l|}{Terminology}                                  & \multicolumn{1}{l|}{Unit}                                            & \multicolumn{1}{l|}{\multirow{-2}{*}{Other Plans*}}                  & \multicolumn{1}{l|}{Terminology}                                  & \multicolumn{1}{l|}{Unit}                               & \multicolumn{1}{l|}{\multirow{-2}{*}{Other Plans*}} & \multicolumn{1}{l|}{Period or Value}                \\ \hline
\multicolumn{1}{|l|}{Windows Azure}              & \multicolumn{1}{l|}{\cellcolor[HTML]{9AFF99}Virtual Server}       & \multicolumn{1}{l|}{\cellcolor[HTML]{9AFF99}/hr}                     & \multicolumn{1}{l|}{\cellcolor[HTML]{9AFF99}1}                       & \multicolumn{1}{l|}{\cellcolor[HTML]{9AFF99}Azure Storage}        & \multicolumn{1}{l|}{\cellcolor[HTML]{9AFF99}/GB  month} & \multicolumn{1}{l|}{\cellcolor[HTML]{9AFF99}1}      & \multicolumn{1}{l|}{\cellcolor[HTML]{9AFF99}90 day} \\ \hline
\end{tabular}
\end{table}


After I removed \multicolumn, I got errors for \multirow{-2}{p{1cm}}{Other Plans*}

 main.tex, line 37
Missing number, treated as zero.

p
l.37 ...    & \multirow{-2}{p{1 cm}}{Other Plans*}
& Termin...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
p
l.37 ...    & \multirow{-2}{p{1 cm}}{Other Plans*}
& Termin...
Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!


See page 2 of the full example https://www.overleaf.com/read/ywhjzprxmrgj

• \multicolumn{1}{|l|}{...} overrides the p{1cm}. If you want to see an effect, drop the \multicolumns. – marmot Oct 18 '18 at 3:38

A couple of possibilities which don't generate an overfull \hbox with a standard article documentclass:

\documentclass{article}
\usepackage{array}
\renewcommand{\arraystretch}{2}
\usepackage{multirow}
\usepackage[table]{xcolor}
\usepackage{makecell}

\begin{document}
\begin{table}\scriptsize\centering
\begin{tabular}{llllllll}
\hline
& Compute & \makecell[l]{Pay As\\ You Go} & & Storage & \makecell[l]{Pay As\\ You Go} &  & Trail \\
\cline{2-3} \cline{5-6} \cline{8-8}
\multirow{-2}{*}{Provider} & Terminology & Unit & \multirow{-2}{*}{\makecell[l]{Other\\ Plans*}} & Terminology & Unit  & \multirow{-2}{*}{\makecell[l]{Other\\ Plans*}} & \makecell[l]{Period\\ or Value} \\
\hline
\hline
\end{tabular}
\end{table}
\begin{table}\tiny\centering
\begin{tabular}{|l|l|l|l|l|l|l|l|}
\hline
& Compute & \makecell[l]{Pay As\\ You Go} & & Storage & \makecell[l]{Pay As\\ You Go} &  & Trail \\
\cline{2-3} \cline{5-6} \cline{8-8}
\multirow{-2}{*}{Provider} & Terminology & Unit & \multirow{-2}{*}{\makecell[l]{Other\\ Plans*}} & Terminology & Unit  & \multirow{-2}{*}{\makecell[l]{Other\\ Plans*}} & \makecell[l]{Period\\ or Value} \\
\hline
\hline
\end{tabular}
\end{table}
\end{document}


Please note that, for colored cells, I've used an appropriate tabular instead of \makecell.

I prefer the first, without vertical rules:

• since you not provide any information of your document page layout it is not possible to see how much your table spill-out on right text area border
• limiting table width to width of text is the best make with use of tabular*, tabularx or one of others similar table environments and for them prescribe desired table width
• with this environments you need to select appropriate column types, for example p{<width>} or X
• don't use makecell with colored table. you can experienced unexpected troubles

see if the following suggestion solve your problem:

\documentclass{article}
\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage{cellspace, multirow, tabularx}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}

\renewcommand\tabularxcolumn[1]{m{#1}}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}

%-------------------------------------- only for show page layout
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.25pt}
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}
\begin{table}[htb]
\setlength\extrarowheight{2pt}
\begin{tabularx}{\linewidth}{L
*{2}{>{\hsize=1.2\hsize}L L >{\hsize=0.8\hsize}L}
L}
\hline
&   Compute
&   Pay As You Go
&   &   Storage
&   Pay As You Go
&   &   Trail               \\
\cline{2-3} \cline{5-6} \cline{8-8}
\multirow{-2.8}{=}{Provider}
&   Terminology
&   Unit
&   \multirow{-2.8}{=}{Other Plans*}
&   Terminology
&   Unit
&   \multirow{-2.8}{=}{Other\\ Plans*}
& Period or Value       \\
\hline
\rowcolor{green!30}
\cellcolor{white}{Windows Azure}
&   Virtual  Server
&   /hr
& 1 &  Azure Storage
&   /GB mont
& 1 &  90 day               \\
\hline
\end{tabularx}
\end{table}
\end{document}


it gives:

(red lines indicate page layout)

if you have narrower text area, than see, if reducing font size can help you.

• For colored cells, I've used a tabular instead of \makecell. – CarLaTeX Nov 6 '18 at 16:31
• @CarLaTeX, i observe this :-). you wrote nice answer (+1) ... – Zarko Nov 6 '18 at 17:08
• I got 2 errors after I moved the table to my big document: Illegal unit of measure; Missing number treated as zero. I can't figure out what is causing it, it works fine in the simple illustration. – Miranda Feb 28 at 14:03
• @Miranda, without knowing what you doing in your document, i cant say anything. apparently you have in it some error not related to my table code. anyway, you select other answer ... – Zarko Feb 28 at 14:21
• Thanks, I have updated Table 5 in overleaf.com/read/ywhjzprxmrgj, but couldn't replicate the error, I suspect my package is clashing with this solution. I choose the other answer because it doesn't require me to change my existing setting, although I initially thought your solution looks better :( – Miranda Feb 28 at 14:34

I found an option from the original site, to scale table to text width.

I end up doing this:

% required packages to your document preamble:
\usepackage{graphicx}

\resizebox{\textwidth}{!}{
\begin{tabular}
% original table
\end{tabular}
}

• You should not =use \resizebox – it leads to inconsistent font sizes. – Bernard Oct 18 '18 at 8:07
• But I can't figure out the how to get rid of the errors for \multirow – Miranda Oct 18 '18 at 22:46