在tabularx中对齐列

11

我希望能够正确对齐最后一列,因为在结尾处存在额外的空间。请告诉我如何做到这一点。谢谢。

\documentclass[11pt]{article}
\usepackage{setspace}                                   %double spacing and spacing in tables                           
\usepackage{amsmath}                                    %equations etc. in latex
\usepackage[capposition=top]{floatrow}                  %so that the caption for figures appear at the top
\usepackage[tablename=TABLE,figurename = FIGURE,labelsep=newline,aboveskip=0pt,font=bf,justification=centering]{caption}   %so that caption looks cool
\usepackage{booktabs}                                   %midrule etc. which adds space around lines. Make tables look good. 
\usepackage{tabularx}                                   %use tabularx environment for creating one page tables
\usepackage[margin=1in]{geometry}                       %defining the margin for the page
\usepackage[autostyle]{csquotes}                        %for quotes. alternative would be " and "
\usepackage[table]{xcolor}                              %rowcolor, cellcolor, color for references
\usepackage{pdflscape}                                  %landscape and keep the pages straight
\usepackage{everypage}                                  %For AddEveryHookPage
\usepackage{hanging}                                    %For references
\usepackage{longtable}                                  %For multiple pages
\usepackage{multirow}                                   %Valuable package as can be seen from table 5,8, and 10
\usepackage{graphicx}                                   %created line using this package
\usepackage{bm}                                         %bold and italics in the math enviornment at the same time
\usepackage{dcolumn} % a package actually used in this example

\def\hang{\par\noindent\makebox[1.5em][l]{ }\hangindent1.5em} %hanging indent  

\makeatletter
\setlength{\@fptop}{0pt}                                %to make tables and figures start at the top of the page
\makeatother

\newcommand{\Lpagenumber}{\ifdim\textwidth=\linewidth\else\bgroup       %to correct the page numbering for landscape pages
    \dimendef\margin=0
    \ifodd\value{page}\margin=\oddsidemargin
    \else\margin=\evensidemargin
    \fi
    \raisebox{\dimexpr -\topmargin-\headheight-\headsep-0.5\linewidth}[0pt][0pt]{%
        \rlap{\hspace{\dimexpr \margin+\textheight+\footskip}%
            stabu            \llap{\rotatebox{90}{\thepage}}}}%
    \egroup\fi}
\AddEverypageHook{\Lpagenumber}%                        %to correct the page numbering for landscape pages


\newcolumntype{Y}{>{\centering\arraybackslash}X}        %to center the columns for tabularx environment
\newcolumntype{Z}{>{\centering\arraybackslash}p{0.75in}}    %to center the columns for tabularx environment
\newcolumntype{K}{>{\centering\arraybackslash}p{0.3in}} %to center the columns for tabularx environment
\newcommand{\gmc}[3]{\multicolumn{#1}{@{}#2@{}}{#3}}    %short form for multicolumn
\doublespacing                                          %make lines double spaced



\begin{document}
    \setcounter{page}{-1} %start numbering at page 3 (2 - n where n = -1)
    \thispagestyle{empty} %suppress page number

    \begingroup % keep any font size changes local to group
    \captionof{table}{\textbf{Descriptive Statistics}}
    \singlespacing
    \footnotesize
    \centering
    \setlength\tabcolsep{3pt} %default
    \renewcommand{\arraystretch}{1}


    \begin{tabularx}{\textwidth}{@{\extracolsep{\fill}}l*{2}{c}}
        \gmc{3}{l}{\textbf{Panel A: Sample Representation across Economic Sectors}} \\\midrule   
        \textbf{Sector} & \textbf{N} & \textbf{\% Frequency} \\\midrule
        Energy & 524 & 1.65\%                       \\
        Materials & 2,648 & 8.34\%                  \\
        Industrials & 5,905   &     18.60\%             \\
        Consumer Discretionary & 5,549  & 17.48\%       \\
        Consumer Staples & 2,174 & 6.85\%       \\
        Health Care & 5,167 & 16.28\%               \\
        Financials & 0 & 0.00\%             \\
        Information Technology & 9,774 & 30.79\%        \\
        Telecommunication Services & 0 & 0.00\% \\
        Utilities & 0 & 0.00\%              \\\midrule
        Total & 31,741 & 100.00\%               \\\midrule
    \end{tabularx}
    \endgroup

\end{document} 
1个回答

0
如果你只是想让最后一列没有空间,你可以替换

。该内容与编程有关。
    \begin{tabularx}{\textwidth}{@{\extracolsep{\fill}}l*{2}{c}}

使用:

    \begin{tabularx}{\textwidth}{l Y r}

@oretisis 我想让这一列居中。但是有额外的尾随空格,我想要去掉它。 - Sumit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接