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 have a csv file formatted like this one:

"","head 1","head 2","head 3"
"count 1","23","24","25"
"percentage 1","23%","24%","25%"
"count 2","53","54","55"
"percentage 2","53%","54%","55%"

I'm using datatool package to convert csv to table. I want to format the table to right-align. But right-align only works when the csv is formatted like this one:
"row 2","23","24","25"

I know I can manually adjust the table to get what I need. But the csv file is dynamic (the csv file is generated by the system).

How can I get a right-aligned table, fix the csv source or fix the LaTeX?


This is my the sample LaTeX code:

\documentclass[a4paper]{article}

\usepackage[small,compact]{titlesec}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{palatino}

\usepackage{datatool}

\begin{document}

\section{CSV Test}

\DTLloaddb{csvtest}{csvtest.csv}            
\begin{table}[htbp]
\centering
\DTLdisplaydb{csvtest}              
\caption{CSV Table Test}        
\end{table}

\end{document}

And the csv:

"","Head 1","Head 2"
"Count 1","15","99"
"","1.92\%","12.69\%"
"Count 2","33","353"
"","1.99\%","21.28\%"
share|improve this question
    
How about making a script to pre-process your csv file? –  ℝaphink Apr 29 '11 at 8:11
    
Welcome to tex.sx! It's not necessary to sign your questions (as there is already a box with your username below it) or to begin them with a greeting. –  doncherry Apr 29 '11 at 8:47
    
Can you add a minimal document that shows what you've done that doesn't work? (The document should load only datatool, read in a minimal CSV file and attempt to format it the way you want.) –  Alan Munn Apr 29 '11 at 11:07
    
The answer section is for solutions to the question only. I moved the example code to the question. You can edit it to provide more information one posted. You can and should also use <pre>...</pre> HTML tags around non-TeX code like CSV instead of `...`<br>. –  Martin Scharrer Apr 29 '11 at 14:30

1 Answer 1

\DTLloaddb{csvtest}{csvtest.csv}            
\begin{table}[htbp]
\centering
\renewcommand{\dtlstringalign}{r}
\DTLdisplaydb{csvtest}              
\caption{CSV Table Test}        
\end{table}

The quoted entries are interpreted by datatool as strings, so you need to help the package by telling it how to align strings.

share|improve this answer

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.