表格格式 - 寬度

表格格式 - 寬度

好吧,我在使用乳膠表時遇到了一些麻煩。我試圖在已經提出的問題中找到解決方案,但我無法理解或讓這些問題發揮作用。這是我的表代碼:

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

表格看起來不錯,但它向右延伸得太遠,幾乎到達頁面邊緣。我需要一種方法來解決這個問題。我嘗試在表格命令中使用 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 命令,以使其看起來更像真正的化學公式。

相關內容