表格列的宽度由 m{} 设置,看起来不正确

表格列的宽度由 m{} 设置,看起来不正确

我正在使用 R 和 Sweave 为报告生成表格,但生成的表格之一的m{}列宽定义不太好。R .tex/Sweave 生成​​的文件包含以下代码(我已将这些行改为乱码以保护报告内容)。

% PREAMBLE
\documentclass[11pt,letterpaper]{article}                           % Set the document class, paper size, font
\usepackage[top=1in,bottom=1in,left=0.75in,right=0.75in]{geometry}  % Using geometry to set the margins
\usepackage{lscape}                                                 % Using lscape to help rotate pages as needed
\usepackage{color}                                                  % Lets us define colors
\usepackage{colortbl}                                               % Lets us colorize our tables
\usepackage{threeparttable}                                         % Supposedly allows us to have notes on tables
\usepackage{array}                                                  % Allows for more precision in table layouts
\usepackage{hhline}                                                 % Grants access to hhline
\usepackage{xcolor}                                                 % Alternate rows of color

% COLORS
\definecolor{mydarkgrey}{RGB}{96,96,96}
\definecolor{mygrey}{RGB}{224,224,224}

% BEGIN DOCUMENT
\begin{document}
\setlength{\parindent}{0mm}             % Remove indentation
\setlength{\arrayrulewidth}{1.1pt}      % Makes the lines look nicer in tables
\SweaveOpts{concordance=TRUE}           % For Sweave

\begin{table}[htb]
\centering
\caption{Table Caption}
\vspace{12pt}
\begin{threeparttable}
\rowcolors{2}{mygrey}{}
\begin{tabular}{|>{\raggedright\arraybackslash}m{3.7in}| %
                >{\centering\arraybackslash}m{0.54in}| %
                >{\centering\arraybackslash}m{0.54in}| %
                >{\centering\arraybackslash}m{0.54in}| %
                >{\centering\arraybackslash}m{0.54in}| %
                >{\centering\arraybackslash}m{0.54in}| %
                >{\centering\arraybackslash}m{0.54in}|}
\hline
\rowcolor{mydarkgrey}
  \color{white}A & \color{white}B & \color{white}\% & \color{white}C & \color{white}\% & \color{white}D & \color{white}\% \\
  Non-significant issue in the issues & 0 & 0 & 0 & 0 & 0 & 0 \\
  Significant issue in the things & 0 & 0 & 0 & 0 & 0 & 0 \\
  Loss of losses & 0 & 0 & 0 & 0 & 0 & 0 \\
  Returning to the consent document & 1 & 25.0 & 0 & 0 & 0 & 0 \\
  Substantive logical fallacies & 0 & 0 & 0 & 0 & 0 & 0 \\
  Duplicated replication of disease & 3 & 75.0 & 0 & 0 & 1 & 50 \\
  Fantastical subgenus & 0 & 0 & 0 & 0 & 0 & 0 \\
  Deviant characteristics consistent w/James' syndrome & 0 & 0 & 0 & 0 & 0 & 0 \\
  Scores $\ge$ 10 with Cohen's adjustment\tnote{2} & 1 & 25 & 0 & 0 & 1 & 50 \\
  Centralized optimization context > 5\tnote{2} & 0 & 0 & 0 & 0 & 0 & 0 \\
  Subdermal O$^{2}$ desat rate <85\% for >10\% of the record\tnote{3} & 0 & 0 & 0 & 0 & 0 & 0 \\
  Other & 3 & 75 & 0 & 0 & 1 & 50 \\
  Total & 4 & 100 & 0 & 0 & 2 & 50 \\ \hline
\end{tabular}
\begin{tablenotes}[flushleft]
\scriptsize \item[] \textit{Percentages are given by column, excepting the final total.}
\item[] \textit{Percentages will not total to 100.}
\item[1] \textit{Note 1.}
\item[2] \textit{Note 2.}
\item[3] \textit{Note 3.}
\end{tablenotes}
\end{threeparttable}
\end{table}
\normalsize

\end{document}

根据我的计算,3.7 英寸 + 6*(0.54 英寸) 应该是 6.94 英寸,应该正好适合我的 7 英寸页面区域(\the\linewidth宽度为 505.89 pts,即 7 英寸)。但是,我的输出是这样的:

在此处输入图片描述

最后 6 列的宽度似乎不是 0.54 英寸,我不确定为什么。我也尝试以 pts 为单位指定宽度,但同样的问题仍然存在,就像我将列类型更改为 而p{}不是时一样m{}

答案1

您可以使用以下内容作为tabular列规范:

\begin{tabular}{|>{\raggedright\arraybackslash}m{\dimexpr 3.7in-2\tabcolsep-2\arrayrulewidth}| %
                *{6}{>{\centering\arraybackslash}m{\dimexpr 0.54in-2\tabcolsep-\arrayrulewidth}|}}

它会删除\tabcolsep列两侧的(2\tabcolsep对于每一列而言),并\arrayrulewidth在必要时加上(第一列的左侧和右侧,而第二至第七列也会删除右侧规则)。

Sweave 的输出是自动化的,导致列规范中的重复。但是,列规范的精简使用*{<num>}{<col spec>}来自/由array包裹

相关内容