LyX ⇒ Table Challenge
Table Challenge
Dear list
As a newbie with Lyx/Latex I would like to know if there is any way that the following can be accomplished.
I currently have some R code which produces amongst other things a table with about 80 rows or more in 5 col.
Since this does not fit on an A4 page, I split the table in Excel and then copy / paste into Word.
I have used Lyx to do some work and have managed to get Sweave working with Lyx so would like to now try and automate the whole process.
My question is can Lyx\Latex layout the table in the same way as I currently do by hand withou any manual intervention.
Please see the attachment for a sample of the before and after of what I do.
Any assistance in this regard wouold be welcomed.
Regards
Steve
As a newbie with Lyx/Latex I would like to know if there is any way that the following can be accomplished.
I currently have some R code which produces amongst other things a table with about 80 rows or more in 5 col.
Since this does not fit on an A4 page, I split the table in Excel and then copy / paste into Word.
I have used Lyx to do some work and have managed to get Sweave working with Lyx so would like to now try and automate the whole process.
My question is can Lyx\Latex layout the table in the same way as I currently do by hand withou any manual intervention.
Please see the attachment for a sample of the before and after of what I do.
Any assistance in this regard wouold be welcomed.
Regards
Steve
- Attachments
-
- TableChallenge.pdf
- (25.9 KiB) Downloaded 338 times
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Table Challenge
The table looks pretty easy. Getting the data into LaTeX would probably be best using datatool or pgfplotstable, with the raw data exported by Excel as a CSV or tab-separated file. Options for the table itself are pgfplotstable (again) or siunitx.
A small example version (in LaTeX) would be:
As I say, you can include the data automatically using for example datatool. If you could post an example CSV I can probably do a more complete example.
A small example version (in LaTeX) would be:
Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage{booktabs,siunitx}\begin{document}\sisetup{tabformat=-1.2}\begin{tabular}{lSSSS}\topruleID & {{A}} & {{B}} & {ZBW} & {ZWI} \\\midrule4er66 & 2.30 & 2.30 & 2.44 & 0.00 \\4gcyi & 1.82 & 1.88 & -0.07 & -1.24 \\5ycya & {{\#}} & {{\#}} & {N/A} & {N/A} \\\bottomrule\end{tabular}\end{document}
Last edited by josephwright on Wed Jan 20, 2010 11:13 pm, edited 1 time in total.
Joseph Wright
Re: Table Challenge
Hi Joseph
Thanks for the reply and the interest.
I have attached a sample data file in single five col format.
If you have the time to try and get it into the format I need that would be great.
Regards
Steve
Thanks for the reply and the interest.
I have attached a sample data file in single five col format.
If you have the time to try and get it into the format I need that would be great.
Regards
Steve
- Attachments
-
- SampleDataSingleCol.csv
- (1.86 KiB) Downloaded 309 times
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Table Challenge
Perhaps
You'll need to make a very slight edit to your raw data: the first column needs to be called "labid" here, with no underscore.
Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage{booktabs,colortbl,datatool,siunitx,xtab}\DTLloadrawdb{data}{SampleDataSingleCol.csv}\begin{document}\begin{center}\sisetup{dp=2,numdiv=,tabformat=-1.2}\begin{xtabular}{lSSSS@{}l}\topruleID & A & B & ZBW & ZWI &\DTLforeach*{data}{%\DTLlabid=labid,%\DTLA=A,%\DTLB=B,%\DTLZBW=ZBW,%\DTLZWI=ZWI%}{%\DTLiffirstrow {\\ \midrule}{\\ \DTLifoddrow{}{\rowcolor[gray]{.9}}}%\DTLlabid & \DTLA & \DTLB & \DTLZBW & \DTLZWI &} \\\bottomrule\end{xtabular}\end{center}\end{document}
Joseph Wright
Re: Table Challenge
Hi Joseph
Thanks fot the reply
Looking at the datatool manual, which is very comprehensive, I found the example with the split table. Unfortunatley it's very difficult with Latex to really track what all the functions do, so many thanks for spotting my request and putting two and two together.
I need to update MikTex/Lyx so that I can use datatool and the other packages referred to in you example, but once I have done so I will try your suggested code and see how it goes.
Once again thanks for your interest
Regards
Steve
Thanks fot the reply
Looking at the datatool manual, which is very comprehensive, I found the example with the split table. Unfortunatley it's very difficult with Latex to really track what all the functions do, so many thanks for spotting my request and putting two and two together.
I need to update MikTex/Lyx so that I can use datatool and the other packages referred to in you example, but once I have done so I will try your suggested code and see how it goes.
Once again thanks for your interest
Regards
Steve
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Re: Table Challenge
That's what things like The LaTeX Companion are for, but datatool, siunitx and pgfplotstable are all too new to appear there. So there is a place for asking about!
Joseph Wright
Re: Table Challenge
Hi Joseph
Sorry but I am back again.
The attached file is the output that I get after running your code. I made the change to lab_id to labid as per your last post
No error messages but it seems clear to me that the \DTLloadrawdb{data} does not work as intended. I have the csv file in the same directory as the Lyx file.
Should it be in another folder ?
I am using Lyx 1.6.2 and MikTex 2.7
Any ideas
Regards
Steve
Sorry but I am back again.
The attached file is the output that I get after running your code. I made the change to lab_id to labid as per your last post
No error messages but it seems clear to me that the \DTLloadrawdb{data} does not work as intended. I have the csv file in the same directory as the Lyx file.
Should it be in another folder ?
I am using Lyx 1.6.2 and MikTex 2.7
Any ideas
Regards
Steve
- Attachments
-
- TableChallenge1.pdf
- (3.78 KiB) Downloaded 330 times
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Re: Table Challenge
Not being a Lyx user, I'm a bit limited on what I can suggest. I used exactly the LaTeX code I posted here, with the CSV file edited to use "labid" with no underscore. The attached PDF is the result using an up to date TeX Live 2009 system. Do you get any errors in the log?
- Attachments
-
- untitled.pdf
- Typeset table
- (38.17 KiB) Downloaded 254 times
Joseph Wright
Re: Table Challenge
Interesting!!!
I have taken a look at the log and from what I can see the following is the problem, as I suspected, but unfortunately I am not sure why.
"Package datatool Warning: File `SampleDataSingleCol.csv' has no data on input l
ine 21."
I have also attached the log, Maybe you can see something else.
Also I notice that there is only single set of col's in your pdf, I would have thought that there was going to be two as per the datatool manual pg47.
Thanks once again for your interest.
Regards
Steve
I have taken a look at the log and from what I can see the following is the problem, as I suspected, but unfortunately I am not sure why.
"Package datatool Warning: File `SampleDataSingleCol.csv' has no data on input l
ine 21."
I have also attached the log, Maybe you can see something else.
Also I notice that there is only single set of col's in your pdf, I would have thought that there was going to be two as per the datatool manual pg47.
Thanks once again for your interest.
Regards
Steve
- Attachments
-
- lyx-latex log ver1.txt
- (13.91 KiB) Downloaded 280 times
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Table Challenge
I suspect that you've got the CSV file open in something like Excel, so it can't be read by TeX. I've attached the CSV file I used (including the edit): try that one.
On the two-column question, it's a bit challenging but can be done.
The most awkward part is the row number: you can't just use \DTLifoddrow, so instead there has to be a calculation which I've based on the low-level counter datatool uses for rows. The attached PDF is the result: I hope it suits.
On the two-column question, it's a bit challenging but can be done.
Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage{booktabs,colortbl,datatool,siunitx}\DTLloadrawdb{data}{SampleDataSingleCol.csv}\begin{document}\begin{center}\sisetup{dp=2,numdiv=,tabformat=-1.2}\begin{tabular}{lSSSSlSSSS@{}l}\topruleID & A & B & ZBW & ZWI & ID & A & B & ZBW & ZWI &\DTLforeach*{data}{%\DTLlabid=labid,%\DTLA=A,%\DTLB=B,%\DTLZBW=ZBW,%\DTLZWI=ZWI%}{%\DTLifoddrow{%\DTLiffirstrow{\\\midrule}{\\}%\ifodd \numexpr (\value{DTLrowi} - 1)/2 \relax\rowcolor[gray]{.9}\fi}{}%\DTLlabid & \DTLA & \DTLB & \DTLZBW & \DTLZWI &} \\\bottomrule\end{tabular}\end{center}\end{document}
- Attachments
-
- temp.pdf
- Two columns and coloured
- (37.48 KiB) Downloaded 260 times
-
- SampleDataSingleCol.csv
- The raw data, slightly edited
- (1.65 KiB) Downloaded 308 times
Joseph Wright