You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LaTeX表格列内边距调整求助:解决表格适配textwidth问题

LaTeX表格适配textwidth的解决方案

问题描述

我试了各种方法都没用,实在找不到原因……我有个9列的tabular表格,目前唯一能让它适配textwidth的办法是用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}

方法1:用tabularx自动适配宽度(推荐)

tabularx可以让表格自动填充到指定宽度,无需缩放字体。先导入包,定义居中的自适应列类型,再替换原表格环境:

\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X} % 定义居中的自适应列

\begin{table}
    \centering
    \begin{tabularx}{\textwidth}{|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{tabularx}
    \caption{Resumen de los valores de $i$ destacados, obtenidos mediante diferentes métodos.}
    \label{resultados finales}
\end{table}

方法2:微调列间距与字体大小

如果不想用新包,可通过缩小列间距+轻微调整字体大小来适配,不会像adjustbox那样模糊:

\begin{table}
    \centering
    \small % 轻微缩小字体,不影响可读性
    \setlength{\tabcolsep}{4pt} % 调小默认列间距(默认6pt)
    \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}
    \caption{Resumen de los valores de $i$ destacados, obtenidos mediante diferentes métodos.}
    \label{resultados finales}
\end{table}

方法3:修复手动内边距的竖线对齐问题

你之前的竖线错位是因为@{\hspace}覆盖了默认列间距,且\multicolumn的格式没匹配列定义。调整列定义和\multicolumn的格式即可:

\begin{table}
    \centering
    % 给每列左右都加内边距,同时保留竖线
    \begin{tabular}{|@{\hspace{0.5em}}c@{\hspace{0.5em}}|@{\hspace{0.5em}}c@{\hspace{0.5em}}|@{\hspace{0.5em}}c@{\hspace{0.5em}}|@{\hspace{0.5em}}c@{\hspace{0.5em}}|@{\hspace{0.5em}}c@{\hspace{0.5em}}|@{\hspace{0.5em}}c@{\hspace{0.5em}}|@{\hspace{0.5em}}c@{\hspace{0.5em}}|@{\hspace{0.5em}}c@{\hspace{0.5em}}|@{\hspace{0.5em}}c@{\hspace{0.5em}}|}
       \multicolumn{1}{c}{} &  \multicolumn{4}{@{\hspace{0.5em}}c@{\hspace{0.5em}}|}{Conjunto de datos original}  & \multicolumn{4}{@{\hspace{0.5em}}c}{Conjunto de datos reducido} \\
        \cline{2-9}
       \multicolumn{1}{@{\hspace{0.5em}}c@{\hspace{0.5em}}|}{} & 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}
    \caption{Resumen de los valores de $i$ destacados, obtenidos mediante diferentes métodos.}
    \label{resultados finales}
\end{table}

内容的提问来源于stack exchange,提问作者Peybol

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 15:08:11