表格列大小寬度不適合所有內容

表格列大小寬度不適合所有內容

我正在使用以下程式碼,基於如何使用 siunitx 在表中使用帶有 SI 單位的字母建立一個表。

我怎樣才能使專欄足夠寬以適應內容。尺寸列設定的最佳方法是什麼?

在此輸入影像描述

\begin{table}[!htp] % not just 'h!'
\centering % not a center environment
\begin{tabular}{
        @{}
        l
        S[table-format=1.1]
        S[table-format=1.3]
        S[table-format=1.2]
        S[table-format=1.2]
        S[table-format=1.2]
        @{}
    }
    \toprule
    Inductor &
    {$size$} &
    {$inductance$} &
    {$sensitivity$} &
    {$dc resistance d$} &
    {$SRF$}\\
    &
    {(\si{\milli\meter})} &
    {(\si{\milli\henry})} &
    {(\si{\milli\volt\per\ampere\meter})} &
    {(\si{\ohm})} &
    {(\si{\kilo\hertz})} \\
    \midrule
    Premo       &8.6x3x2.7 &18.5 &90 &165 &300  \\
    TDK         &7x12x33   &8.6   &23 &112 &135     \\
    \bottomrule
\end{tabular}
\label{tab:inductor}

\end{table}

答案1

在標準線寬下,表格稍微有點滿,所以我使用了一個tabular*技巧;您需要檢查這是否有效以及柱間空間是否足夠,否則您可能會求助於\small.

第二列不是S,但你應該使用\num它的條目。正確設定其他列的位數。

請不要對斜體使用數學模式:它不是用於此目的的。

\documentclass[a4paper]{article}
\usepackage{amsmath,siunitx,booktabs}

\begin{document}

\begin{table}[htp]
\centering

\setlength{\tabcolsep}{0pt} % let TeX do the calculations
\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  c
  S[table-format=2.1]
  S[table-format=2.0]
  S[table-format=3.0]
  S[table-format=3.0]
  @{}
}
\toprule
Inductor &
  {\itshape size} &
  {\itshape inductance} &
  {\itshape sensitivity} &
  {\itshape DC resistance $d$} &
  {\itshape SRF}\\
&
  {(\si{\milli\meter\cubed})} &
  {(\si{\milli\henry})} &
  {(\si{\milli\volt\per\ampere\meter})} &
  {(\si{\ohm})} &
  {(\si{\kilo\hertz})} \\
\midrule
Premo & \num{8.6x3x2.7} & 18.5 & 90 & 165 & 300 \\
TDK   & \num{7x12x33}   &  8.6 & 23 & 112 & 135 \\
\bottomrule
\end{tabular*}

\caption{A table}\label{xyz}

\end{table}

\end{document}

在此輸入影像描述

答案2

對大小列使用 S 列說明符沒有任何實際意義。但是,{...}如果列單元格中沒有數字,請使用該表示法,當然,請使用正確的數字規格:3.1 ( iii.d) 為三個整數和一個小數保留空間

\documentclass[a4paper, 12pt]{article}
\usepackage{amsmath,siunitx,booktabs}

\begin{document}

\begin{tabular}{
        @{}
        l
        S[table-format=1.1]
        S[table-format=2.1]
        S[table-format=2.1]
        S[table-format=3.1]
        S[table-format=3.1]
        @{}
    }
    \toprule
    Inductor &
    {\itshape size} &
    {\itshape inductance} &
    {\itshape sensitivity} &
    {\itshape dc resistance d} &
    {\itshape SRF}\\
    &
    {(\si{\milli\meter})} &
    {(\si{\milli\henry})} &
    {(\si{\milli\volt\per\ampere\meter})} &
    {(\si{\ohm})} &
    {(\si{\kilo\hertz})} \\
    \midrule
    Premo       &{8.6x3x2.7} &18.5 &90 &165 &300  \\
    TDK         &{7x12x33}   &8.6   &23 &112 &135     \\
    \bottomrule
\end{tabular}

\結束{文件}

在此輸入影像描述

相關內容