Graphics, Figures & Tablesdcolumn | Combination of Digits and Characters

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
sjkiss
Posts: 30
Joined: Tue Nov 15, 2011 12:23 am

dcolumn | Combination of Digits and Characters

Post by sjkiss »

Hi,

I've generated the following table using apsrtable (R) and it works excellent, except for the table cells that mix characters with digits (e.g. the tables cells in the "Wald" row).

The code is generated by a call to sprintf in R, but that does not seem to be the problem. I've used the same function to generate latex code that works with regular text. The problem appears to be mixing characters and and digits in a single table cell. I've tried hard-encoding white space with curly braces, but that doesn't work. I think the problem might be that the table is constructed in dcolumn.
Can any one offer any suggestions?
Simon Kiss

Code: Select all

\documentclass{article}
\usepackage{dcolumn}
\begin{document}
\begin{table}[!ht]
\caption{Comparing Model Fit Of Non vs. Repeated EVents}
\label{} 
\begin{tabular}{ l D{.}{.}{2}D{.}{.}{2} } 
\hline 
  & \multicolumn{ 1 }{ c }{ Non-repeated Events } & \multicolumn{ 1 }{ c }{ Repeated Events } \\ \hline
 %                    & Non-repeated Events  & Repeated Events     \\ 
Environmentalism     & 2.46 ^{***}          & 2.18 ^{**}          \\ 
                     & (0.73)               & (0.70)              \\ 
Partisanship         & -0.36                & -0.31               \\ 
                     & (0.37)               & (0.36)              \\ 
Professionalism      & 0.91                 & 0.75                \\ 
                     & (0.94)               & (0.59)              \\ 
Avg. Health Stories  & 0.66 ^{**}           & 0.50 ^*             \\ 
                     & (0.21)               & (0.21)               \\
 $N$                  & 468                  & 468                 \\ 
Wald                 & 28 {on 4 df}, p = 0.00 & 20 on 4 df, p = 0.00\\ 
Log-Likelihood       & -354.79              & -311.02             \\ 
$R^2$                & 0.11 (Max 0.80)    & 0.07  (Max  0.75)    \\ \hline
 \multicolumn{3}{l}{\footnotesize{Robust standard errors in parentheses}}\\
\multicolumn{3}{l}{\footnotesize{$^\dagger$ significant at $p<.10$; $^* p<.05$; $^{**} p<.01$; $^{***} p<.001$}} 
\end{tabular} 
 \end{table}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

dcolumn | Combination of Digits and Characters

Post by localghost »

The excellent siunitx package is preferable in this case. The manual shows in detail how to handle tabular material like this.


Thorsten
sjkiss
Posts: 30
Joined: Tue Nov 15, 2011 12:23 am

Re: dcolumn | Combination of Digits and Characters

Post by sjkiss »

That would be a possibility, except that this code is generated via an R function that takes the regression coefficients from a fitted model. So it would be quite extensive to modify that R function to use an entirely different Latex package. It would be useful if there was some simple, minimal change I could put into to the Latex code to accomplish this.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

dcolumn | Combination of Digits and Characters

Post by localghost »

Define a new column type in the preamble of your document which is flexible regarding the format of the digits.

Code: Select all

\newcolumntype{d}[1]{D{.}{.}{#1}}
For details about this please refer to the dcolumn manual.

Modify your table preamble with respect to this new column type and insert the necessary number of integers and decimals before and after the period, respectively. For example

Code: Select all

\begin{tabular}{ld{4.5}d{4.5}} \hline
% table body
\end{tabular}
This reserves the necessary space for four integers before and five decimals behind the period. It serves only as an idea and probably needs some adjustment.
Post Reply