LyX ⇒ Table Challenge
Table Challenge
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 337 times
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Table Challenge
A small example version (in LaTeX) would be:
Code: Select all
\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}
\sisetup{tabformat=-1.2}
\begin{tabular}{lSSSS}
\toprule
ID & {{A}} & {{B}} & {ZBW} & {ZWI} \\
\midrule
4er66 & 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}
Re: Table Challenge
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 308 times
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Table Challenge
Code: Select all
\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}
\toprule
ID & 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}
Re: Table Challenge
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
Re: Table Challenge
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 329 times
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Re: Table Challenge
- Attachments
-
- untitled.pdf
- Typeset table
- (38.17 KiB) Downloaded 253 times
Re: Table Challenge
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
On the two-column question, it's a bit challenging but can be done.
Code: Select all
\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}
\toprule
ID & 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 258 times
-
- SampleDataSingleCol.csv
- The raw data, slightly edited
- (1.65 KiB) Downloaded 307 times