表格格式 - 宽度

表格格式 - 宽度

好吧,我在 Latex 中使用表格时遇到了一些问题。我尝试在已经提出的问题中找到解决方案,但我既无法理解也无法让它们发挥作用。这是我的表格代码:

    \begin{table}[ht]
    \caption{Model Input Information: Materials}
    \centering
    \begin{tabular}{c c c}
    \toprule
    Available Materials & Material Input Parameters & Description \\
    \midrule
        Fused Silica (delta eV = 9) & alpha & Avalanche Coefficient [\si{\cm\squared\per\joule}] \\
        Fused Silica (delta eV = 7.5) & delta eV & Material Band Gap [\si{\electronvolt}] \\
        \ce{GaAs} & me & Effective Electron Mass [\si{\kilogram}] \\
        \ce{ZnSe} & n0 & Linear Refractive Index \\
        \ce{Ge} & n2 & Non-Linear Refractive Index \\
        \ce{HfO_2} & T & Effective Decay Constant [fs] \\
        \ce{TiO_2} & & \\
        \ce{Ta_2O_5} & & \\
        \ce{Al_2O_3} & & \\
        \ce{SiO_2} & & \\
    \bottomrule
    \end{tabular}
    \label{table:MaterialInputs}
    \end{table}

表格看起来不错,但它向右延伸得太远了,几乎到了页面的边缘。我需要一种方法来解决这个问题。我尝试在 tabular 命令中使用 p 来手动设置宽度,但我不喜欢它在换行时所做的操作。它会在单词上创建连字符,而不是将它们放在一行上。

任何建议将不胜感激!

答案1

这显示了具有不规则设置的固定宽度列:

\documentclass{article}

\usepackage{array,mhchem,booktabs,siunitx}% please don't leave it to people to guess these

\begin{document}

    \begin{table}[htp]% don't forget p
    \caption{Model Input Information: Materials}
    \centering
    \begin{tabular}{
 >{\raggedright\arraybackslash}p{4cm}
 c
 >{\raggedright\arraybackslash}p{2.5cm}}
    \toprule
    Available Materials & Material Input Parameters & Description \\
    \midrule
        Fused Silica (delta eV = 9) & alpha & Avalanche Coefficient [\si{\cm\squared\per\joule}] \\
        Fused Silica (delta eV = 7.5) & delta eV & Material Band Gap [\si{\electronvolt}] \\
        \ce{GaAs} & me & Effective Electron Mass [\si{\kilogram}] \\
        \ce{ZnSe} & n0 & Linear Refractive Index \\
        \ce{Ge} & n2 & Non-Linear Refractive Index \\
        \ce{HfO_2} & T & Effective Decay Constant [fs] \\
        \ce{TiO_2} & & \\
        \ce{Ta_2O_5} & & \\
        \ce{Al_2O_3} & & \\
        \ce{SiO_2} & & \\
    \bottomrule
    \end{tabular}
    \label{table:MaterialInputs}
    \end{table}

\end{document}

答案2

您可以使用makecell包:它允许您更改单元格中的行,定义列标题的命令,并且可以放大行的垂直间距(通常太紧)。我还添加了包caption,因此标题和表格之间的垂直间距也变大了。

        \documentclass[a4paper,10pt]{article}
        \usepackage[utf8]{inputenc}
        \usepackage[T1]{fontenc}
        \usepackage{lmodern}
        \usepackage{array, booktabs}
        \usepackage{siunitx}
        \usepackage{makecell}
        \usepackage{caption}
        \def\ce#1{\ensuremath{\mathrm{#1}}}

        \begin{document}

        \begin{table}[ht]
        \caption{Model Input Information: Materials}
        \centering
        \renewcommand{\theadfont}{\normalsize\bfseries}
        \begin{tabular}{ccc}
        \toprule
        \thead{Available Materials} & \thead{Material Input Parameters} & \thead{Description} \\
        \midrule
            \makecell*{Fused Silica\\ (delta eV = 9)} & alpha & \makecell{Avalanche Coefficient\\{ [\si{\cm\squared\per\joule}]}} \\
            \makecell*{Fused Silica\\ (delta eV = 7.5)} & delta eV & \makecell{Material Band Gap\\{[\si{\electronvolt}]}} \\
            \makecell*{\ce{GaAs}} & me & Effective Electron Mass [\si{\kilogram}]\\
            \makecell*{\ce{ZnSe}} & n0 & Linear Refractive Index \\
            \makecell*{\ce{Ge}} & n2 & Non-Linear Refractive Index \\
            \makecell*{\ce{HfO_2}} & T & Effective Decay Constant [fs] \\
            \makecell*{\ce{TiO_2}} & & \\
            \makecell*{\ce{Ta_2O_5}} & & \\
            \makecell*{\ce{Al_2O_3}} & & \\
            \makecell*{\ce{SiO_2}} & & \\
        \bottomrule
        \end{tabular}
        \label{table:MaterialInputs}
        \end{table}

        \end{document} 

在此处输入图片描述

注意:由于我没有安装 mhchem 包,因此我重新定义了 \ce 命令以使其看起来更像真正的化学公式。

相关内容