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'm using estout (esttab actually) to produce a table in Latex from Stata. I'm using the dcolumn package to align the decimal places in my table.

I want to override the alignment for a single row; to be specific the number of observations row. Is there a way of doing this? Or, equivalents, if there a way to prefix each element in a row with "\multicolumn{1}{c}{" and suffix with "}", which would override the dcolumn alignment?

Example:

\begin{table}[htbp]\centering
\caption{My Table}
\begin{tabular}{l*{3}{D{.}{.}{-1}}}
\toprule        
                    &\multicolumn{1}{c}{Mean/s.d.}&\multicolumn{1}{c}{Mean/s.d.}&\multicolumn{1}{c}{Mean/s.d.}\\
\midrule
Var A               &        8.68&        8.51&        8.92\\
                    &        2.42&        2.51&        2.26\\
Var B               &        2.14&        1.98&        2.37\\
                    &        1.33&        1.29&        1.35\\
\midrule
Observations        &       38040&       22054&       15986\\
\bottomrule
\end{tabular}
\end{table}

Thanks!

share|improve this question
    
Someone should move this to TeX - LaTeX, you'll get quicker and better answers there. –  Stéphane Gimenez Jul 30 '11 at 14:06
add comment

migrated from stackoverflow.com Aug 1 '11 at 4:58

This question came from our site for professional and enthusiast programmers.

2 Answers

The excellent siunitx package would make things a bit easier.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[tableposition=top]{caption}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
  \begin{table}[!ht]
    \caption{My Table}
    \centering
    \begin{tabular}{l*{3}{S}}\toprule        
                   & {Mean/s.d.} & {Mean/s.d.} &{Mean/s.d.} \\ \midrule
      Var A        & 8.68        & 8.51        & 8.92       \\
                   & 2.42        & 2.51        & 2.26       \\ \addlinespace
      Var B        & 2.14        & 1.98        & 2.37       \\
                   & 1.33        & 1.29        & 1.35       \\ \midrule 
      Observations & {38040}     & {22054}     & {15986}    \\ \bottomrule
    \end{tabular}
  \end{table}
\end{document}

The additional grouping with curly braces lets the concerned cell content appear as simple text and not as a number to be parsed. Details for customization in the package manual.

share|improve this answer
add comment

Have you tried playing with the layout suboption of stats? It looks like it accepts the text entry, so you might want to try something like

estout ... , stats(N , layout("\multicolumn{1}{c}{@}"))

Hm. If I try it as

    sysuse auto, clear
    reg mpg wei for
    estout , stats(N , layout("\multicolumn{1}{c}{@}"))

it seems to produce the formatting in the variables column, as well. Ah well.

share|improve this answer
    
The stats(.) option does work, but requires a slight modification: stats(N,layout("\multicolumn{1}{c}{@} label("Observations")) - this overrides the multicolumn wrapper around the variable name. Thanks StasK! –  user870029 Aug 3 '11 at 17:46
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.