# How do I fit my specified data into a table which fits within the page limits where the maths doesn't hit the top of each box?

I have made a table that fits my data but not the way I would like. I have mixed and matched different ideas but nothing has worked. There is probably a much simpler way of creating a table with this much data but I don't know how. I want a thin black border around every box. My amsmaths keeps hitting the top of the box making it impossible to read. Is there a way where I could fit it neatly in a 7in width page? Columns 5 and 6 are the worst to fit as I have fractions. This is what it looks like.

\documentclass[10pt]{article}

\usepackage{amsmath,amsfonts,amssymb}
\usepackage[a4paper, total={7in, 10in}]{geometry}
\usepackage{multicol}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{fancyhdr}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{positioning}
\usepackage{array}
\newtheorem{theorem}{Theorem}
\usepackage{color}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{table}[ht]
\centrering
\resizebox{\textwidth}{!}{\begin{tabular}{|M{1cm}|M{2cm}|M{2cm}|M{2cm}|M{5cm}|M{5cm}|M{2cm}|}
\hline

y   & d           & $h_1$ (trapezium) & $h_2$ (isosceles triangle) & Trapezium Area $\frac{c+d}{2}\times h_1$ & Isosceles Area & Total Area  \\[5pt]\hline

0.1 & 1.239378559 & 4.9 & 0.1 & $\frac{5.12+1.239}{2}\times15.5907148$ & $\frac{1.239\times0.1}{2}=0.06196892795$ & 15.65268373 \\[5pt]\hline

0.5 & 2.57400435  & 4.5 & 0.5 & $\frac{5.12+2.574}{2}\times4.5=17.32091161$ & $\frac{2.574\times0.5}{2}$ & 17.96441272 \\[7pt]\hline

1   & 3.364274683 & 4 & 1  & $\frac{5.12+3.36}{2}\times=16.97690637$ & $\frac{3.36\times1}{2}=1.682137342$ & 18.65904368  \\[5pt]\hline

2   & $\frac{4\pi}{3}$ & 3  & 2  & $\frac{5.12+\frac{4\pi}{3}}{2}\times3=13.96945306$ & $\frac{\frac{4\pi}{3}\times2}{2}$ & 18.15824327 \\[5pt]\hline

3   & 4.637117923 & 2  & 3 & $\frac{5.12+4.64}{2}\times2=9.761296424$ & $\frac{4.637\times3}{2}=6.955676885$ & 16.74180653 \\[5pt]\hline

4   & 4.923837669 & 1  & 4 & $\frac{5.12+4.924}{2}\times1=5.1024008085$ & $\frac{4.924\times4}{2}=9.847675338$ & 14.87168342\\[5pt]\hline

\end{tabular}}

\caption{Area of a variety of sized trapezium and isosceles triangles within the cross=section of wine glass.}
\end{table}

\end{document}

• Please note that any modern table design never uses vertical lines and I'd also drop all horizontal except line 1,2 and the last one. Once that is done, I'd load the booktabs package and replace thise three horizontal lines by \toprule, \midrule and \bottomrule Sep 15 at 10:38
• Simplest answer: Dispense with all horizontal lines, and there are no more lines for the math-y stuff to bump into in the first place.
– Mico
Sep 15 at 11:48
• By all means do also replace \centrering with \centering.
– Mico
Sep 15 at 13:14

The package nicematrix allows a very simple code and test changes of the style without changing the contents. It will center the contents of the cells vertically.

(1) We use the natural width of the columns.

(2) To fit the table to the width of the page, we change the font to small instead of using resizebox, and reduce the columns separation a bit.

(3) The command \Block{}{...} allows to use \\ inside to reduce the width of the third and fourth headers.

(4) We add the general directive cell-space-limits=10pt to expand the cell vertically.

(5) We test having borders in each cell using hvlines. In the second table, using hlines instead, we evaluate the appearance with only horizontal lines and also shorter cells.

\documentclass[10pt]{article}

\usepackage{amsmath,amsfonts,amssymb}
\usepackage[a4paper, total={7in, 10in}, showframe]{geometry} % added showframe <<<
\usepackage{multicol}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{fancyhdr}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{positioning}
\usepackage{array}
\newtheorem{theorem}{Theorem}
\usepackage{color}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}% not used

\begin{document}

\begin{table}[ht]
\centering
\small
\setlength{\tabcolsep}{5pt} % default 6pt

\begin{NiceTabular}{cccclcc}[cell-space-limits=10pt, hvlines]   % expand the cells + all lines

y   & d& \Block{}{$h_1$ \\(trapezium)} & \Block{}{$h_2$ \\ (isosceles \\ triangle)} & Trapezium Area $\frac{c+d}{2}\times h_1$  & Isosceles Area & Total Area  \\

0.1 &1.239378559        &4.9&0.1&$\frac{5.12+1.239}{2}\times15.5907148$             &$\frac{1.239\times0.1}{2}=0.06196892795$   &15.65268373\\

0.5 &2.57400435         &4.5&0.5&$\frac{5.12+2.574}{2}\times4.5=17.32091161$        &$\frac{2.574\times0.5}{2}$                 &17.96441272\\

1   &3.364274683        &4  &1  &$\frac{5.12+3.36}{2}\times=16.97690637$            &$\frac{3.36\times1}{2}=1.682137342$        &18.65904368\\

2   &$\frac{4\pi}{3}$   &3  &2  &$\frac{5.12+\frac{4\pi}{3}}{2}\times3=13.96945306$ &$\frac{\frac{4\pi}{3}\times2}{2}$          &18.15824327\\

3   &4.637117923        &2  &3  &$\frac{5.12+4.64}{2}\times2=9.761296424$           &$\frac{4.637\times3}{2}=6.955676885$       &16.74180653\\

4   &4.923837669        &1  &4  &$\frac{5.12+4.924}{2}\times1=5.1024008085$         &$\frac{4.924\times4}{2}=9.847675338$       &14.87168342\\

\end{NiceTabular}

\caption{Area of a variety of sized trapezium and isosceles triangles within the cross=section of wine glass.}
\end{table}

\begin{table}[ht]
\centering
\small
\begin{NiceTabular}{cccclcc}[cell-space-limits=8pt, hlines]     % expand the cells + only horizonal lines

y   & d& \Block{}{$h_1$ \\(trapezium)} & \Block{}{$h_2$ \\ (isosceles \\ triangle)} & Trapezium Area $\frac{c+d}{2}\times h_1$  & Isosceles Area & Total Area  \\

0.1 &1.239378559        &4.9&0.1&$\frac{5.12+1.239}{2}\times15.5907148$             &$\frac{1.239\times0.1}{2}=0.06196892795$   &15.65268373\\

0.5 &2.57400435         &4.5&0.5&$\frac{5.12+2.574}{2}\times4.5=17.32091161$        &$\frac{2.574\times0.5}{2}$                 &17.96441272\\

1   &3.364274683        &4  &1  &$\frac{5.12+3.36}{2}\times=16.97690637$            &$\frac{3.36\times1}{2}=1.682137342$        &18.65904368\\

2   &$\frac{4\pi}{3}$   &3  &2  &$\frac{5.12+\frac{4\pi}{3}}{2}\times3=13.96945306$ &$\frac{\frac{4\pi}{3}\times2}{2}$          &18.15824327\\

3   &4.637117923        &2  &3  &$\frac{5.12+4.64}{2}\times2=9.761296424$           &$\frac{4.637\times3}{2}=6.955676885$       &16.74180653\\

4   &4.923837669        &1  &4  &$\frac{5.12+4.924}{2}\times1=5.1024008085$         &$\frac{4.924\times4}{2}=9.847675338$       &14.87168342\\

\end{NiceTabular}

\caption{Area of a variety of sized trapezium and isosceles triangles within the cross=section of wine glass.}
\end{table}

\end{document}


Alternative. A similar result is obtained using the package makecell to expand the cells and shortening the headers with \thead{...}.

\documentclass[10pt]{article}

\usepackage{amsmath,amsfonts,amssymb}
\usepackage[a4paper, total={7in, 10in}, showframe]{geometry}
\usepackage{multicol}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{fancyhdr}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{positioning}
\usepackage{array}
\newtheorem{theorem}{Theorem}
\usepackage{color}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\setcellgapes{10pt}% expand cells vertically

\begin{document}

\begin{table}[ht]
\centering

\resizebox{\textwidth}{!}{%
\makegapedcells %<<<<<<<<<<<<<<<<<
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline

y   & d           &\thead{ $h_1$ \\ (trapezium)} &\thead{ $h_2$ \\ (isosceles \\triangle)} &\thead{Trapezium Area \\ $\frac{c+d}{2}\times h_1$}& Isosceles Area & Total Area  \\[-5pt]\hline

0.1 & 1.239378559 & 4.9 & 0.1 & $\frac{5.12+1.239}{2}\times15.5907148$ & $\frac{1.239\times0.1}{2}=0.06196892795$ & 15.65268373 \\\hline

0.5 & 2.57400435  & 4.5 & 0.5 & $\frac{5.12+2.574}{2}\times4.5=17.32091161$ & $\frac{2.574\times0.5}{2}$ & 17.96441272 \\\hline

1   & 3.364274683 & 4 & 1  & $\frac{5.12+3.36}{2}\times=16.97690637$ & $\frac{3.36\times1}{2}=1.682137342$ & 18.65904368  \\\hline

2   & $\frac{4\pi}{3}$ & 3  & 2  & $\frac{5.12+\frac{4\pi}{3}}{2}\times3=13.96945306$ & $\frac{\frac{4\pi}{3}\times2}{2}$ & 18.15824327 \\\hline

3   & 4.637117923 & 2  & 3 & $\frac{5.12+4.64}{2}\times2=9.761296424$ & $\frac{4.637\times3}{2}=6.955676885$ & 16.74180653 \\\hline

4   & 4.923837669 & 1  & 4 & $\frac{5.12+4.924}{2}\times1=5.1024008085$ & $\frac{4.924\times4}{2}=9.847675338$ & 14.87168342\\\hline

\end{tabular}
}

\caption{Area of a variety of sized trapezium and isosceles triangles within the cross=section of wine glass.}
\end{table}

\end{document}