对齐表格中的列
Posted
技术标签:
【中文标题】对齐表格中的列【英文标题】:Aligning column in tabularx 【发布时间】:2017-01-23 07:10:07 【问题描述】:我想正确对齐最后一列。最后还有多余的空间。请让我知道该怎么做。谢谢。
\documentclass[11pt]article
\usepackagesetspace %double spacing and spacing in tables
\usepackageamsmath %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
\usepackagebooktabs %midrule etc. which adds space around lines. Make tables look good.
\usepackagetabularx %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
\usepackagepdflscape %landscape and keep the pages straight
\usepackageeverypage %For AddEveryHookPage
\usepackagehanging %For references
\usepackagelongtable %For multiple pages
\usepackagemultirow %Valuable package as can be seen from table 5,8, and 10
\usepackagegraphicx %created line using this package
\usepackagebm %bold and italics in the math enviornment at the same time
\usepackagedcolumn % a package actually used in this example
\def\hang\par\noindent\makebox[1.5em][l] \hangindent1.5em %hanging indent
\makeatletter
\setlength\@fptop0pt %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\valuepage\margin=\oddsidemargin
\else\margin=\evensidemargin
\fi
\raisebox\dimexpr -\topmargin-\headheight-\headsep-0.5\linewidth[0pt][0pt]%
\rlap\hspace\dimexpr \margin+\textheight+\footskip%
stabu \llap\rotatebox90\thepage%
\egroup\fi
\AddEverypageHook\Lpagenumber% %to correct the page numbering for landscape pages
\newcolumntypeY>\centering\arraybackslashX %to center the columns for tabularx environment
\newcolumntypeZ>\centering\arraybackslashp0.75in %to center the columns for tabularx environment
\newcolumntypeK>\centering\arraybackslashp0.3in %to center the columns for tabularx environment
\newcommand\gmc[3]\multicolumn#1@#2@#3 %short form for multicolumn
\doublespacing %make lines double spaced
\begindocument
\setcounterpage-1 %start numbering at page 3 (2 - n where n = -1)
\thispagestyleempty %suppress page number
\begingroup % keep any font size changes local to group
\captionoftable\textbfDescriptive Statistics
\singlespacing
\footnotesize
\centering
\setlength\tabcolsep3pt %default
\renewcommand\arraystretch1
\begintabularx\textwidth@\extracolsep\filll*2c
\gmc3l\textbfPanel A: Sample Representation across Economic Sectors \\\midrule
\textbfSector & \textbfN & \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
\endtabularx
\endgroup
\enddocument
【问题讨论】:
【参考方案1】:如果您只是希望它没有最后一列的空间,您可以 替换
\begintabularx\textwidth@\extracolsep\filll*2c
与:
\begintabularx\textwidthl Y r
【讨论】:
@oretisis 我希望列居中。但是有多余的尾随空格,我想删除它。以上是关于对齐表格中的列的主要内容,如果未能解决你的问题,请参考以下文章