Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using R and Sweave to produce tables for a report, and one of the generated tables is not playing nicely with the m{} definition of column width. The .tex file produced by R/Sweave has the following code (I've changed the lines to gibberish to protect the content of the report).

% 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}

By my math, 3.7in + 6*(0.54in) should be 6.94 inches, which should fit nicely inside the 7 inch page area that I have (\the\linewidth says that the width is 505.89 pts, which is 7 inches). However, my output is this:

enter image description here

The width of the last 6 columns doesn't appear to be 0.54in, and I'm not sure why. I tried designating the widths in pts as well, and the same problem persists, as it does when I changed the column type to p{} instead of m{}.

share|improve this question
1  
Try \begin{tabular}{|>{\raggedright\arraybackslash}m{3.7in}|*{6}{@{}>{\centering\ar‌​raybackslash}m{0.54in}@{}|}} –  tohecz Dec 4 '12 at 18:59
    
And Welcome to TeX.SX! –  tohecz Dec 4 '12 at 18:59
1  
You have 2*\tabcolsep+\arrayrulewidth between each column and \tabcolsep+\arrayrulewidth at either side –  David Carlisle Dec 4 '12 at 19:09
    
By far this is my best experience yet on StackExchange. You guys provided me exactly what I needed to adjust things. Perfect. Thanks so much! –  TARehman Dec 4 '12 at 19:26
add comment

1 Answer

up vote 4 down vote accepted

You can use the following for your tabular column specification:

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

which removes the \tabcolsep on either side of a column (so 2\tabcolsep for each column), plus the \arrayrulewidth where necessary (left & right for the first column, while the second to seventh columns removes the right rule as well).

The output of Sweave is automated, leading to the duplication within the column specification. However, the condensed use of the column specification *{<num>}{<col spec>} is from/provided by the array package.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.