4

I primarily a Word user, but use LaTeX now and then. One thing I don't like working with in LaTeX is tables. My data might come from Excel (usually), Word, or the output of some custom program.

If my data source is Excel, I use some xls2Latex macro (that I downloaded somewhere) to do the job for me.

However, I am wondering, is there any good, general workflow for easily getting your data in a LaTeX tables? Do you modify your programs to directly output to LaTeX format, or do you e.g. output to csv first and then use a csv to latex script?

And how do you update it? By hand directly in LaTex, or do you rerun your whatever-to-LaTeX script?

4
  • 1
    Have you tried datatool package?
    – user11232
    Mar 2, 2012 at 11:10
  • @Dr Harish Kumar: No :-) Mar 2, 2012 at 11:40
  • This question may be of some help.
    – user11232
    Mar 2, 2012 at 14:45
  • As far as editing a pre-existing table, I like LyX for getting all of the cell borders right. But LyX does not have great tools for pasting a table in yet.
    – scottkosty
    Mar 3, 2012 at 6:19

1 Answer 1

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .