调整列宽 tabularx + 表格边距

调整列宽 tabularx + 表格边距

从以下 MWE 中可以看出,单独调整几列的宽度确实很棒。此外,如果需要,我该如何减少表格的页边距?

\documentclass{article}
%\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabularx}{\textwidth}{>{\raggedleft\arraybackslash}XXXXX}
    \addlinespace
    \toprule
    \multicolumn{1}{c}{Variable } & Source & Spatial coverage & Temporal coverage & Frequency \\
    \midrule
    Urban Social Disturbances & USDAA, PRIO, Oslo & 55 cities (49 countries) & 1960-2010 & Event-based \\
    Local food prices & FAO GIEWS database  & 43 markets (in common with USDAA) & 1990-Present (unbalanced) & Monthly \\
    Total population & WDI 2010, World Bank & 190 countries & 1960-2011 & Annual \\
    Urban population (as p.c. of total) & WDI 2010, World Bank & 190 countries & 1960-2011 & Annual \\
    Internet penetration & WDI 2010, World Bank & 177 countries & 1960-2011 & Annual \\
    Percapita GDP (constant, 2000 level) & WDI 2010, World Bank & 248 countries & 1960-2011 & Annual \\
    Index of democracy & QoG database, U of Gothenberg & 202 countries & 1960-2011 & Annual \\
    \bottomrule
    \end{tabularx}%
  \label{tab:addlabel}%
\end{table}%


\end{document}

答案1

这会使某些列比其他列更宽,使所有列左右不平整,并使表格比页面更宽。您可能需要摆弄数字以获得所需的外观: 在此处输入图片描述

\documentclass{article}
%\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{calc}
\begin{document}

\begin{table}[htbp]
  \caption{Add caption}
  \noindent\hspace*{-1cm}\begin{tabularx}{\textwidth+2cm}{
>{\raggedleft\arraybackslash\advance\hsize1em}X
>{\raggedright\arraybackslash\advance\hsize1em }X
>{\raggedright\arraybackslash}X
>{\raggedright\arraybackslash\advance\hsize-1em }X
>{\raggedright\arraybackslash\advance\hsize-1em }X
}
    \addlinespace
    \toprule
    \multicolumn{1}{c}{Variable } & Source & Spatial coverage & Temporal coverage & Frequency \\
    \midrule
    Urban Social Disturbances & USDAA, PRIO, Oslo & 55 cities (49 countries) & 1960-2010 & Event-based \\
    Local food prices & FAO GIEWS database  & 43 markets (in common with USDAA) & 1990-Present (unbalanced) & Monthly \\
    Total population & WDI 2010, World Bank & 190 countries & 1960-2011 & Annual \\
    Urban population (as p.c. of total) & WDI 2010, World Bank & 190 countries & 1960-2011 & Annual \\
    Internet penetration & WDI 2010, World Bank & 177 countries & 1960-2011 & Annual \\
    Percapita GDP (constant, 2000 level) & WDI 2010, World Bank & 248 countries & 1960-2011 & Annual \\
    Index of democracy & QoG database, U of Gothenberg & 202 countries & 1960-2011 & Annual \\
    \bottomrule
    \end{tabularx}\hspace*{-1cm}%
  \label{tab:addlabel}%
\end{table}%

\noindent aaa\dotfill aaa


\noindent aaa\dotfill aaa



\end{document}

答案2

对于更高级的列定义,您可以使用tabu。下面的代码使前两列的宽度是其他列的两倍。X[3,c]将为您提供一个居中的列,其宽度是 1 单位列的三倍,后者是根据表格宽度动态计算的(如您的示例中所示\textwidth)。

\usepackage{booktabs}
\usepackage{tabu}

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabu} to \textwidth {X[2,l]
                                X[2,l]
                                X[1,l]
                                X[1,l]
                                X[1,l]}
    \addlinespace
    \toprule
    \multicolumn{1}{c}{Variable } & Source & Spatial coverage & Temporal coverage & Frequency \\
    \midrule
    Urban Social Disturbances & USDAA, PRIO, Oslo & 55 cities (49 countries) & 1960-2010 & Event-based \\
    \bottomrule
    \end{tabu}
    \label{tab:addlabel}%
\end{table}%

相关内容