El ancho del tamaño de la columna tabular no se ajusta a todo el contenido.

El ancho del tamaño de la columna tabular no se ajusta a todo el contenido.

Estoy usando el siguiente código, basado enCómo usar letras con unidad SI en la tabla usando siunitxpara crear una tabla.

¿Cómo puedo hacer que la columna sea lo suficientemente ancha para que se ajuste al contenido? ¿Cuál es la mejor manera de configurar la columna de dimensiones?

ingrese la descripción de la imagen aquí

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

Respuesta1

Con un ancho de línea estándar, la tabla está ligeramente llena, así que utilizo un tabular*truco; Tendrás que comprobar si esto funciona y si el espacio entre columnas es adecuado; de lo contrario, puedes recurrir a \small.

La segunda columna no es S, pero debes usarla \numpara sus entradas. Establezca correctamente el número de dígitos para las otras columnas.

Por favor, no utilice el modo matemático para cursiva: no está diseñado para ese propósito.

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

ingrese la descripción de la imagen aquí

Respuesta2

No tiene mucho sentido utilizar un especificador de columna S para la columna de tamaño. Sin embargo, use la notación {...}si no tiene un número en la celda de la columna y, por supuesto, use las especificaciones adecuadas para los números: 3.1 ( iii.d) reserva espacio para tres números enteros y un decimal

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

\end{documento}

ingrese la descripción de la imagen aquí

información relacionada