Here is a possible solution to your similar-width panel in tables by means of the tabularx
package. It provides the environment tabularx
that takes an argument specifying the width of the tabularx
. That allows one to typeset the two panels as two separate tables but still maintain the same width across both tables. To stretch it across the entire width of the text, I used \linewidth
. A new column type Y
was defined as a right-aligned (\raggedleft
) version of the stretchable X
column type provided by tabularx
. Also, the booktabs
package was loaded in order to improve the table layout.
\documentclass{article}
\usepackage[margin=2cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}% raggedleft column X
\begin{document}
\begin{table}[htb]
\caption{Descriptive Statistics and Correlations for Variables}
\label{tbl:stats-and-correlations}
\begin{tabularx}{\linewidth}{l*{6}{Y}}
\toprule
\multicolumn{7}{l}{\textbf{Panel A: Descriptive Statistics}} \\
\midrule
& Mean & Median & St.\ Dev. & IQR & 25$^{\textrm{th}}$ & 75$^{\textrm{th}}$ \\[0pt]
& & & & & Percentile & Percentile \\
Variable 1 & 12.3 & 45.6 & 7.89 & 5 & 12.0 & 0.22 \\
Variable 2 & 8.3 & 1.0 & 0.01 & 12 & 99.9 & 10.0 \\
\ldots & & & & & &
\end{tabularx}
\begin{tabularx}{\linewidth}{l*{7}{Y}}
\toprule
\multicolumn{7}{l}{\textbf{Panel B: Correlations}} \\
\midrule
& Var.\ 1 & Var.\ 2 & Var.\ 3 & Var.\ 4 & Var.\ 5 & Var.\ 6 & Var.\ 7 \\
Variable~1 & 0.78 & 0.37 & 0.48 & 0.10 & 0.13 & 0.58 & 0.41 \\
Variable~2 & 0.46 & 0.86 & 0.96 & 0.44 & 0.15 & 0.56 & 0.31 \\
Variable~3 & 0.03 & 0.75 & 0.11 & 0.44 & 0.71 & 0.06 & 0.26 \\
Variable~4 & 0.21 & 0.25 & 0.38 & 0.88 & 0.24 & 0.52 & 0.46 \\
Variable~5 & 0.20 & 0.93 & 0.54 & 0.96 & 0.55 & 0.82 & 0.62 \\
Variable~6 & 0.67 & 0.85 & 0.74 & 0.99 & 0.27 & 0.48 & 0.85 \\
Variable~7 & 0.82 & 0.89 & 0.68 & 0.06 & 0.02 & 0.30 & 0.10 \\
\bottomrule
\end{tabularx}
[1]\ Footnote 1: Variable~1 is calculated as\ldots \endgraf
[2]\ Correlations are Pearson.
\end{table}
\end{document}

Minor adjustments to the column alignment, spacing and typesetting is possible.
I teach statistics and have used R with Sweave to create a LaTeX file for a Standard Normal Cumulative Distribution table. This works very well for computed tables. The package datatool package is superior for preexisting tabular information. (Although you could input the data into R and reformat with some additional work. Here is Rnw file for creating a standard normal cumulative distribution table.
\documentclass[letterpaper,12pt]{article}
\usepackage{amsmath}
\usepackage[margin=.5in]{geometry}
\pagestyle{empty}
\begin{document}
%%% Adapted from a file written by Ross Ihaka (One of the Original R Developers)
%%% --- Customisation of Sweave layout
\DefineVerbatimEnvironment{Sinput}{Verbatim} {xleftmargin=2em}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{xleftmargin=2em}
\DefineVerbatimEnvironment{Scode}{Verbatim}{xleftmargin=2em}
\DefineVerbatimEnvironment{verbatim}{Verbatim}{xleftmargin=2em}
% These definitions eliminate the space between the input and
% output in the man-machine dialog.
\fvset{listparameters={\setlength{\topsep}{0pt}}}
\renewenvironment{Schunk}{\vspace{\topsep}}{\vspace{\topsep}}
%%% --- End of customisation
\title{\textbf{Computing the Normal \\ Distribution Function}}
%%% --- Customisation of R printing and graphical layout
<<echo=false>>=
options(width=60)
options(continue=" ")
options(SweaveHooks=list(fig=function()
par(mar=c(4.1, 4.1, .1, 2.1))))
ntableb =
function(cols = 1:length(y)) {
x = seq(0, 3.4, by = .1)
y = seq(0, .09, by = .01)
p = round(outer(x, y, function(x, y) pnorm(x+y)), 4)
cat("\\begin{tabular}{|c|c*{",
length(cols)-1,"}{@{\\quad}c}|}\n", sep = "")
cat("\\hline\n")
cat(paste("\\rule{0pt}{12pt}z & ",
paste(sprintf("%.2f", y[cols]), collapse = " & "),
sep = ""), "\\\\\n")
cat("\\hline\n")
for(i in 1:length(x)) {
if (i == 1) cat("\\rule{0pt}{14pt}")
cat(paste(sprintf("%.1f & ", x[i]),
paste(sprintf("%.4f", p[i,cols]),
collapse = " & "),
sep = ""), "\\\\")
if (i %% 5 == 0 || i == length(x)) cat("[5pt]\n") else cat("\n")
}
cat("\\hline\n")
cat("\\end{tabular}\n")
}
@
\parbox[b]{3in}{Standard Normal Curve Areas $P(X\le x)$ \par\vspace{.25in}}\par
\noindent\makebox[\textwidth]{%
<<results=tex,echo=false>>=
ntableb()
@
}
\end{document}
I use TeXmaker and the command loaded in one of the user commands is
R.exe CMD Sweave %.Rnw
Now just compile the resulting *.tex file with pdfatex
Best Answer
Far from perfection, but for a document with a single table you can use
detex
and then replace&
by,
and delete empty lines. In Linux you can use some tools asgrep
andsed
for this. The first line of the table is then the columns types, so you can delete manually or with some tool liketail
. Example command line:Example input
file.tex
:Ouput (
file.csv
):