如何将指定的数据放入适合页面限制的表格中,并且数学运算不会达到每个框的顶部?

如何将指定的数据放入适合页面限制的表格中,并且数学运算不会达到每个框的顶部?

我制作了一个适合我的数据的表格,但不是我想要的那种形式。我混合并搭配了不同的想法,但都没有奏效。可能有更简单的方法来创建包含这么多数据的表格,但我不知道怎么做。我想要每个框周围都有一条细黑边框。我的 amsmaths 总是碰到框的顶部,导致无法阅读。有没有办法可以把它整齐地放在 7 英寸宽的页面中?第 5 列和第 6 列最难放进去,因为我有分数。它看起来是这样的。 在此处输入图片描述

\documentclass[10pt]{article}

\usepackage{amsmath,amsfonts,amssymb}
\usepackage[a4paper, total={7in, 10in}]{geometry}
\usepackage{multicol}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat = newest}
\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}

答案1

该包nicematrix允许使用非常简单的代码并测试样式的更改而不更改内容。它将使单元格的内容垂直居中。

(1)我们使用列的自然宽度。

(2) 为了让表格适合页面的宽度,我们将字体改为 ,small而不是使用resizebox,并稍微减少列间距。

(3)该命令\Block{}{...}允许使用\\inside 来减少第三和第四个标题的宽度。

cell-space-limits=10pt(4)我们添加了垂直扩展单元格的通用指令。

(5)我们使用 测试每个单元格是否带有边框hvlines。在第二个表中hlines,我们使用 来评估只有水平线和较短单元格的外观。

A

\documentclass[10pt]{article}

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

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

\usepackage{nicematrix}% added <<<<<<<<<<

\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}

选择。使用包makecell来扩展单元格并缩短标题可以获得类似的结果\thead{...}

\documentclass[10pt]{article}

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

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

\usepackage{makecell} % added <<<<<<<<<<
\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}

C

相关内容