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 want the the following table to be perfectly centered within the margin, with an approximately even spacing between each column.

 \documentclass[a4paper,11pt]{article}
  \usepackage{color,amsmath,amsfonts,amssymb}
     \usepackage[english]{babel}
  \usepackage{colortbl}
  \usepackage{booktabs,dcolumn,caption}
  \usepackage{expdlist}  %expanded list environment
  \usepackage{longtable} %multipage table
  \usepackage{setspace} %for \singlespacing
  \usepackage{adjustbox} %center tables
  \usepackage{icomma}

  \usepackage[margin=1in]{geometry}
  \usepackage{setspace}
  \setstretch{1}


 \captionsetup{labelsep=newline,singlelinecheck=false} % optional
 \newcolumntype{d}[1]{D{.}{.}{#1}} % "decimal" column type


 \setlength{\LTleft}{0pt}
 \setlength{\LTright}{0pt} %full margins

 \oddsidemargin 0.5cm %
 \evensidemargin 0.5cm %
 \textwidth 15cm %
 \topmargin  -0.2in  %
 \textheight 23.5cm %
 \headheight 15pt %


 \doublerulesep2pt

 \begin{document}


 \footnotesize

 \begin{longtable}{@{} l @{\extracolsep{\fill}} *{2}{d{5}} @{}}
 \caption{Pearson correlations} \\
 \toprule
 & \multicolumn{1}{l}{$(del1,del2)$}
 & \multicolumn{1}{l}{$(del1,del3)$} \\
 \midrule
 \endfirsthead
 \multicolumn{2}{@{}l}{\emph{(continued)}} \\
 \toprule
 & \multicolumn{1}{l}{$(del1,del2)$}
 & \multicolumn{1}{l}{$(del1,del3)$} \\
 \midrule
 \endhead
 \midrule[\heavyrulewidth]
 \multicolumn{3}{r@{}}{\emph{(continued)}}
 \endfoot
 \bottomrule
 \endlastfoot
 Hello                & -0.032(Q>0.671) & 0.036(Q>0.620) \\
 Hello                & -0.032(Q>0.671) & 0.036(Q>0.620) \\
 Hello                & -0.032(Q>0.671) & 0.036(Q>0.620) \\
 Hello                & -0.032(Q>0.671) & 0.036(Q>0.620) \\
 Hello                & -0.032(Q>0.671) & 0.036(Q>0.620) \\
 Hello                & -0.032(Q>0.671) & 0.036(Q>0.620) \\
 Hello                & -0.032(Q>0.671) & 0.036(Q>0.620) \\
 Hello                & -0.032(Q>0.671) & 0.036(Q>0.620) \\
 Hello                & -0.032(Q>0.671) & 0.036(Q>0.620) \\
 \end{longtable}
 %\vspace{-0.8cm}

 {\noindent ....}
 \clearpage



 \end{document}
share|improve this question
    
Try {d{2.13}}. –  Harish Kumar Aug 18 '12 at 5:06
    
@HarishKumar works a tiny bit but it's still very ugly and the spaces between the columns aren't the same. –  user16208 Aug 18 '12 at 7:03
1  
Please cut down your example to be minimal: currently, it's not at all clear to me what you really want here (for example, what's wrong with just a standard tabular?). –  Joseph Wright Aug 18 '12 at 9:11
    
This is nearing minimal. There's probably 3-4 packages that aren't needed but I don't know which ones I'm using (I'm new). This is a 2 page table that I've cut down a lot for this example. What I want is for each column to have even spacing between them and also the columns to not go off the edge of the page. –  user16208 Aug 18 '12 at 9:36

1 Answer 1

up vote 3 down vote accepted

I'm not totally clear on what is required. It looks like you have four data columns: two of the data itself and two of some form of error (or similar). I'd therefore use that structure, with the repeated part using @ from the array package:

\documentclass{article}
\usepackage{array,booktabs,caption,dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}} % "decimal" column type
\makeatletter
\newcommand*{\colspacing}{\hskip \col@sep}
\makeatother
\begin{document}
\begin{table}
  \caption{Pearson correlations} 
  \centering
  \begin{tabular}
    {
      l      % 'Entry' row
      d{2.3} % First data column
      @{\colspacing $(Q > {}$}d{1.3}@{$)$\colspacing} % First 'Q' column
      d{1.3} % Second data column
      @{\colspacing $(Q > {}$}d{1.3}@{$)$\colspacing} % First 'Q' column
    }
    \toprule 
    & \multicolumn{2}{l}{$(del1,del2)$}
    & \multicolumn{2}{l}{$(del1,del3)$} \\
    \midrule
    Hello & -0.032 & 0.671 & 0.036 & 0.620 \\
    Hello & -0.032 & 0.671 & 0.036 & 0.620 \\
    Hello & -0.032 & 0.671 & 0.036 & 0.620 \\
    Hello & -0.032 & 0.671 & 0.036 & 0.620 \\
    Hello & -0.032 & 0.671 & 0.036 & 0.620 \\
    \bottomrule
  \end{tabular}
\end{table}
\end{document}

For the first data column, I've reserved space for two 'digits' before the decimal marker to allow for the negative sign. The other spacings are easy: simply the number of actual digits.

share|improve this answer

Your Answer

 
discard

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