Graphics, Figures & TablesChanging decimal alignment within column

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
bjung
Posts: 4
Joined: Wed May 05, 2010 3:01 am

Changing decimal alignment within column

Post by bjung »

Hi,

I would like to align on different decimals. My table uses two different decimal markers in the same column: the top part uses a period and the bottom part a comma. (The top is fractions, the bottom sample size).

I would like to align on *both* the period and comma. Using -dcolumn- allows aligning on the period, but that means that values with the comma separator stick out on the left.

I paste a table example below. Any suggestions much appreciated!

Thanks Bert

\begin{tabular}{ l c }
coeff1 & 2.213 \\
coeff2 & 5.213 \\
N & 7,123 \\
\end{tabular}

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Changing decimal alignment within column

Post by gmedina »

Hi,

one possible solution would be to define a new column type that aligns the cell contents according to a variable character (declared in the argument of the new type). You declare a decimal point in the table format specification and, with the help of \multicolumn, you can switch to a decimal comma; take a look at the following simple example:

Code: Select all

\documentclass{article}
\usepackage{dcolumn}

\newcolumntype{L}[1]{D{.}{#1}{1,3}}
\newcommand\CommaCell[1]{%
  \multicolumn{1}{L{,}}{#1}%
}

\begin{document}

\begin{tabular}{ l L{.} }
  coeff1 & 2.213 \\
  coeff2 & 5.213 \\
  N & \CommaCell{7.123} \\
  O & \CommaCell{9.123} \\
\end{tabular}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply