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.

<to be read again> 
                   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).
<to be read again> 
                   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

  • 2
    \multicolumn{1}{|l|}{...} overrides the p{1cm}. If you want to see an effect, drop the \multicolumns. – marmot Oct 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
\makecell[l]{Windows\\ Azure} & \cellcolor[HTML]{9AFF99}{\renewcommand{\arraystretch}{1}\begin{tabular}{@{}l@{}}Virtual\\ Server\end{tabular}} & \cellcolor[HTML]{9AFF99}/hr & \cellcolor[HTML]{9AFF99}1 & \cellcolor[HTML]{9AFF99}{\renewcommand{\arraystretch}{1}\begin{tabular}{@{}l@{}}Azure\\Storage\end{tabular}}  & \cellcolor[HTML]{9AFF99}{\renewcommand{\arraystretch}{1}\begin{tabular}{@{}l@{}}/GB\\month\end{tabular}} & \cellcolor[HTML]{9AFF99}1 & \cellcolor[HTML]{9AFF99}90 day \\ 
\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
\makecell[l]{Windows\\ Azure} & \cellcolor[HTML]{9AFF99}{\renewcommand{\arraystretch}{1}\begin{tabular}{@{}l@{}}Virtual\\ Server\end{tabular}} & \cellcolor[HTML]{9AFF99}/hr & \cellcolor[HTML]{9AFF99}1 & \cellcolor[HTML]{9AFF99}{\renewcommand{\arraystretch}{1}\begin{tabular}{@{}l@{}}Azure\\Storage\end{tabular}}  & \cellcolor[HTML]{9AFF99}{\renewcommand{\arraystretch}{1}\begin{tabular}{@{}l@{}}/GB\\month\end{tabular}} & \cellcolor[HTML]{9AFF99}1 & \cellcolor[HTML]{9AFF99}90 day \\ 
\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:

enter image description here

enter image description here

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}
}
  • 5
    You should not =use \resizebox – it leads to inconsistent font sizes. – Bernard Oct 18 at 8:07
  • But I can't figure out the how to get rid of the errors for \multirow – Miranda Oct 18 at 22:46
  • try to use tabular* or tabularx , prescribe table width and allow breaking cell contents into more lines. – Zarko Nov 6 at 15:48
  • 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}
\addparagraphcolumntypes{L}

%-------------------------------------- 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:

enter image description here

(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 at 16:31
  • @CarLaTeX, i observe this :-). you wrote nice answer (+1) ... – Zarko Nov 6 at 17:08
  • Thank you, you too :) – CarLaTeX Nov 6 at 17:14

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.