我几乎尝试了所有方法,但都没有成功,我不知道为什么……我有一个 9 列的表格,我发现让它适合文本宽度的唯一解决方案是使用调整框,但我不喜欢它,因为它似乎会缩放字体。所以我的表格上的数字几乎看不清:

我尝试了其他几种方法,但发现唯一“有效”的方法是手动设置列填充,而不是使用 adjustbox 通过在每个方法中添加:@{\hspace{0.5em}}:

但是,我有那些未对齐的垂直线,我不知道如何处理它…自从我开始解决这个问题已经过去了 4 个小时,但什么也没发生。

我只想调整表格的文本宽度,并通过减少每列的填充来使数字变大。有人能帮我一下吗?谢谢!

\begin{table}
\centering
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
   \multicolumn{1}{c}{} &  \multicolumn{4}{c|}{Conjunto de datos original}  & \multicolumn{4}{c}{Conjunto de datos reducido} \\
    \cline{2-9}
   \multicolumn{1}{c|}{} & Filtro I & Filtro R & Filtro V & Filtros I,R,V & Filtro I & Filtro R & Filtro V & Filtros I,R,V \\

    \hline

   \begin{tabular}[c]{@{}c@{}}$q=0.62$\\ \citep{2007ApJ...662..564B} \end{tabular}  & $43.2_{-4.7}^{+4.2}$ & $41.9_{-3.4}^{+3.6}$ & $47.0_{-6.3}^{+6.3}$ & $41.7^{+3.8}_{-4.1}$ & $41.0_{-3.4}^{+3.5}$ & $45.3_{-4.8}^{+4.1}$ & $42.6_{-4.9}^{+5.8}$ & $45.5^{+4.9}_{-4.9}$ \\
    \hline

    \begin{tabular}[c]{@{}c@{}}$q=0.68$\\ \citep{2017MNRAS.472.2937H} \end{tabular} & $44.6_{-4.0}^{+4.8}$ & $43.1_{-3.6}^{+4.4}$ & $48.8_{-7.1}^{+7.5}$ & $43.0^{+4.5}_{-4.4}$ & $42.2_{-3.6}^{+4.4}$ & $46.5_{-5.5}^{+4.9}$ & $44.0_{-5.3}^{+5.3}$ & $46.8^{+5.6}_{-5.2}$ \\

    \hline

   Bootstrapping & $47.1_{-1.5}^{+1.5}$ & $45.6_{-1.3}^{+1.3}$ & $44.8_{-2.0}^{+2.4}$ & - & $44.0_{-1.3}^{+1.4}$ & $43.0_{-1.3}^{+1.4}$ & $40.3_{-2.7}^{+2.5}$ & - \\

    \hline
\end{tabular}
\end{adjustbox}
\caption{Resumen de los valores de $i$ destacados, obtenidos mediante diferentes métodos.}
\label{resultados finales}
\end{table}

4

  • 1
    欢迎来到 TeX.SE。请告诉我们文本块的宽度。或者,您能否告诉我们您使用的纸张尺寸(US Letter、A4 还是其他尺寸?)以及边距的宽度?


    – 

  • 嗨!谢谢你的帮助 🙂 我对 LaTeX 不是很了解,所以我不知道你在问什么…这有帮助吗? \documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[top=3cm, bottom=1.8cm, left=2cm, right=2cm]{geometry}


    – 

  • 是的,但你应该把它添加到你的问题中的代码中,以及缺失的\begin{document}\usepackage以便人们可以复制代码并查看结果。特别是在这样的问题中,设置\geometry比你例子中的表格更重要,因为你问的是如何让表格适合空间,而不用说空间有多大


    – 

  • 好的,感谢大家的提示和耐心!


    – 


最佳答案
4

只需 (a) 切换到环境tabular*(目标宽度为\textwidth),同时设置\tabcolsep—— 控制列间空白填充量 ——0pt和 (b) 缩短一些标题单元格即可。我还将删除所有垂直规则,并\hline用包的线条绘制宏替换基本指令booktabs。您的读者可能会喜欢表格更开放、更吸引人的“外观”。

\documentclass[12pt,a4paper]{article}
 
%\usepackage[utf8]{inputenc}  % that's the default nowadays
\usepackage[top=3cm,bottom=1.8cm,hmargin=2cm]{geometry}

\usepackage[T1]{fontenc}
\usepackage[spanish,es-tabla]{babel}

\usepackage{array} % for \newcolumntype macro
\newcolumntype{C}{>{$}c<{$}} % automatic math mode

\usepackage[numbers]{natbib} % for \citep macro
\usepackage{booktabs}        % for well-spaced horizontal rules
\newcommand\mytab[1]{\begin{tabular}{l} #1 \end{tabular}} % handy shortcut macro

\begin{document}

\begin{table}
\setlength\tabcolsep{0pt}

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{8}{C} }
\toprule
& \multicolumn{4}{c}{Filtros, Conj.\ de datos original}  
& \multicolumn{4}{c}{Filtros, Conj.\ de datos reducido} \\
\cmidrule(l){2-5} \cmidrule(l){6-9}
& I & R & V & I,R,V & I & R & V & I,R,V \\
\midrule

\mytab{$q{=}0.62$\\ \citep{2007ApJ...662..564B}}
& 43.2_{-4.7}^{+4.2} & 41.9_{-3.4}^{+3.6} 
& 47.0_{-6.3}^{+6.3} & 41.7^{+3.8}_{-4.1} 
& 41.0_{-3.4}^{+3.5} & 45.3_{-4.8}^{+4.1} 
& 42.6_{-4.9}^{+5.8} & 45.5^{+4.9}_{-4.9} \\

\midrule

\mytab{$q{=}0.68$\\ \citep{2017MNRAS.472.2937H}}
& 44.6_{-4.0}^{+4.8} & 43.1_{-3.6}^{+4.4} 
& 48.8_{-7.1}^{+7.5} & 43.0^{+4.5}_{-4.4} 
& 42.2_{-3.6}^{+4.4} & 46.5_{-5.5}^{+4.9} 
& 44.0_{-5.3}^{+5.3} & 46.8^{+5.6}_{-5.2} \\

\midrule

Bootstr. 
& 47.1_{-1.5}^{+1.5} & 45.6_{-1.3}^{+1.3} 
& 44.8_{-2.0}^{+2.4} & \mbox{--} 
& 44.0_{-1.3}^{+1.4} & 43.0_{-1.3}^{+1.4} 
& 40.3_{-2.7}^{+2.5} & \mbox{--} \\

\bottomrule
\end{tabular*}

\caption{Resumen de los valores de i destacados, obtenidos mediante diferentes métodos.}
\label{resultados_finales}
\end{table}

\end{document}

1

  • 谢谢您的回复。这确实是废话,但我并不想缩短这些东西 🙁 但它会让整个表格看起来更清晰。


    – 

考虑将布局从水平(当前)切换为垂直:

\documentclass{article}

\usepackage{makecell,booktabs}

\begin{document}

\begin{figure}
  \centering
  \begin{tabular}{ l l c c c }
    \toprule
    & \multicolumn{1}{c}{Filtro(s)} &
      \makecell[b]{$q = 0.62$ \\ (Bitner et al.~2007)} & % \citep{2007ApJ...662..564B}
      \makecell[b]{$q = 0.68$ \\ (Hill et al.~2017)} & %\citep{2017MNRAS.472.2937H}
      Bootstrapping \\
    \midrule
    \multicolumn{5}{l}{\itshape Conjunto de datos original} \\[0.5em]
    & I       & $43.2_{-4.7}^{+4.2}$ & $44.6_{-4.0}^{+4.8}$ & $47.1_{-1.5}^{+1.5}$ \\[0.5em]
    & R       & $41.9_{-3.4}^{+3.6}$ & $43.1_{-3.6}^{+4.4}$ & $45.6_{-1.3}^{+1.3}$ \\[0.5em]
    & V       & $47.0_{-6.3}^{+6.3}$ & $48.8_{-7.1}^{+7.5}$ & $44.8_{-2.0}^{+2.4}$ \\[0.5em]
    & I, R, V & $41.7^{+3.8}_{-4.1}$ & $43.0^{+4.5}_{-4.4}$ &          --          \\
    \addlinespace
    \multicolumn{5}{l}{\itshape Conjunto de datos reducido} \\[0.5em]
    & I       & $44.0_{-1.3}^{+1.4}$ & $41.0_{-3.4}^{+3.5}$ & $42.2_{-3.6}^{+4.4}$ \\[0.5em]
    & R       & $43.0_{-1.3}^{+1.4}$ & $45.3_{-4.8}^{+4.1}$ & $46.5_{-5.5}^{+4.9}$ \\[0.5em]
    & V       & $42.6_{-4.9}^{+5.8}$ & $44.0_{-5.3}^{+5.3}$ & $40.3_{-2.7}^{+2.5}$ \\[0.5em]
    & I, R, V & $45.5^{+4.9}_{-4.9}$ & $46.8^{+5.6}_{-5.2}$ &          --          \\
    \bottomrule
  \end{tabular}
  \caption{A figure caption}
\end{figure}

\end{document}

1

  • 谢谢你的想法!我想避免这种情况,因为文档中的所有其他表格都遵循相同的水平布局……对于下一个文档,我会考虑到这一点!


    – 

我赞同 Mico 的想法,但我会做一些修改。

首先,数字表总是受益于siunitx;在这种情况下有两个主要原因:

  1. 小数点逗号始终使用,无需信任babel-spanish

  2. 不对称不确定性以更简单、更统一的方式输入。

另一个主要变化是将引文标注放在表格下方的图例中,以节省宝贵的空间。最后,我去掉了缩写和不必要的水平线。

\documentclass[12pt,a4paper]{article}
 
%\usepackage[utf8]{inputenc}  % that's the default nowadays
\usepackage[top=3cm,bottom=1.8cm,hmargin=2cm]{geometry}

\usepackage[T1]{fontenc}
\usepackage[spanish,es-tabla]{babel}

\usepackage[authoryear,round]{natbib} % for \citep macro

\usepackage{booktabs}        % for well-spaced horizontal rules
\usepackage{siunitx}         % for numeric tables

\begin{document}

\begin{table}[htp]
\setlength\tabcolsep{0pt}

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  *{8}{S[table-format=2.1(1)]}
  @{}
}
\toprule
& \multicolumn{8}{c}{Filtros} \\
\cmidrule{2-9}
& \multicolumn{4}{c}{Conjunctos de datos original}  
& \multicolumn{4}{c}{Conjunctos de datos reducido} \\
\cmidrule{2-5} \cmidrule{6-9}
& {I} & {R} & {V} & {I,\,R,\,V} & {I} & {R} & {V} & {I,\,R,\,V} \\
\midrule

$q=0.62$ (a)
& 43.2(42:47) & 41.9(36:34) & 47.0(63:63) & 41.7(38:41) 
& 41.0(35:34) & 45.3(41:48) & 42.6(58:49) & 45.5(40:49) \\

\addlinespace

$q=0.68$ (b)
& 44.6(48:40) & 43.1(44:36) & 48.8(75:71) & 43.0(45:44)
& 42.2(44:36) & 46.5(49:55) & 44.0(53:53) & 46.8(56:52) \\

\addlinespace

Bootstrapping
& 47.1(15:15) & 45.6(13:13) & 44.8(24:20) & {--} 
& 44.0(14:13) & 43.0(14:13) & 40.3(25:27) & {--} \\

\midrule[\heavyrulewidth]

\multicolumn{9}{l}{%
  (a) \citet{2007ApJ...662..564B},\quad
  (b) \citet{2017MNRAS.472.2937H}
}
\end{tabular*}

\caption{Resumen de los valores de i destacados, obtenidos mediante diferentes métodos.}
\label{resultados_finales}

\end{table}

\end{document}

制作说明:我使用虚拟书目数据来匹配图片中的引用。

3

  • 我喜欢它的外观!不知道那个包……我试图将此答案添加到我的文档中,但它在 siunitx 包中给出了一些错误:包 siunitx 错误:无效数字“43.2(42”。这与数字的新格式错误有关,对吗?


    – 


  • @Peybol 很可能你有一个过时的版本


    – 

  • 嗯,我在新文档中尝试了你的代码,它工作正常(我使用的是 overleaf),但在我已有的文档中却不起作用,不知道为什么,也许其他包在做奇怪的事情?我把这个放在 \begin{document} 之前


    – 

我赞同Werneregreg 的想法的结合,但使用 ˙tabularray` 包:

\documentclass[12pt,a4paper]{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,               % for well-spaced horizontal rules
                siunitx}                % for numeric tables

\begin{document}
    \begin{table}[htp]
    \centering
\begin{tblr}{colsep = 10pt, 
             colspec= {@{} ll  *{3}{Q[c, si={table-format=2.1(2)}]} @{}},
             row{1} = {guard, b},
             rowsep = 3pt
            }
    \toprule
    &   Filtro(s)
        &   {$q = 0.62$ \\ (Bitner et al.~2007)} 
            &   {$q = 0.68$ \\ (Hill et al.~2017)} 
                &   Bootstrapping                           \\
    \midrule
\SetCell[c=4]{font=\itshape}  Conjunto de datos original
    &   &   &   &   &                                       \\
    & I         & 43.2(4.2:4.7) & 44.6(4.0:4.8)   & 47.0(1.5:1.5) \\
    & R         & 41.9(3.4:3.6) & 43.1(3.6:4.4)   & 45.6(1.3:1.3) \\
    & I, R, V   & 41.7(3.8:4.1) & 43.0(4.5:4.4)   &   {{{--}}}    \\
    \addlinespace
\SetCell[c=4]{font=\itshape}  Conjunto de datos reducido
    &   &   &   &   &                                  \\
    & I         & 44.0(1.3:1.4) & 41.0(3.4:3.5) &  42.2(3.6:4.4)     \\
    & R         & 43.0(1.3:1.4) & 45.3(4.8:4.1) &  46.5(5.5:4.9)     \\
    & V         & 42.6(4.9:5.8) & 44.0(5.3:5.3) &  40.3(2.7:2.5)     \\
    & I, R, V   & 45.5(4.9:4.9) & 46.8(5.6:5.2) &  {{{--}}}        \\
    \bottomrule
\end{tblr}

\caption{Resumen de los valores de i destacados, obtenidos mediante diferentes métodos.}
\label{resultados_finales}
    \end{table}
\end{document}

1

  • 在在这里提问之前我尝试使用该包,因为它应该处理自动列宽,但我没有成功…谢谢你的例子!


    –