Hot answers tagged

24

Nothing much bad happens if you specify more columns than you use, so if you use {|*{50}{l|}} and no row has more than 3 entries latex doesn't use the extra col spec and just makes a 3 column table.


20

You can use pgfplotstable for this. If you load the array package, you can set the option dec sep align for pgfplotstabletypeset to get the alignment at the decimal point. Padding the numbers with zeros can be accomplished by setting fixed zerofill, the number of decimals can be set using precision, either for all columns or for individual columns by using ...


14

The usual answer here is the pgfplots package, which is based on TikZ. Note that it does not do pie charts, as these are considered misleading by many people. (There is some discussion of this issue in the TikZ manual.) (Note: As mathematicians use 'graphs' for something entirely different, the usual way to refer to data display in a graphical form is as a ...


14

Assuming that the first row is the name of the columns, then you simply need to load the database via \DTLloaddb{myDB}{MyData.csv} where the file MyData.csv contains the contents as shown above, and the you can use the internal function \DTLdisplaydb{myDB} to print it as a table. This table is very wide so I used the geometry package to extend the width of ...


13

My datatool skills are limited, so the following solution uses TeX primitives and PGFs mathematical engine and also its \pgfutil@in@ macro/conditional. Interaction Line 99: Minimum ratio a Cardinal needs to get elected as Pope. \pgfmathparse{2/3*\the\value{sumVotes}} Line 70: Number of Cardinals that will be marked if no one has reached the limit. As ...


11

The datatool package uses an insertion sort algorithm. The gory details, for anyone who's interested, are described in section 4.10 of the datatool documented code. However, I agree with the comments. TeX is a typesetting tool (and a very good one) but there are a lot of things that it's not, which is why datatool has an accompanying helper application ...


10

\documentclass{article} \usepackage{array} \usepackage{longtable} \makeatletter \let\oldref\ref \def\ref#1{\immediate\write\@auxout{\string\expandafter\gdef\noexpand\csname REF:#1\string\endcsname{}}% \oldref{#1}} \def\zz#1#2{\noalign{% \expandafter\ifx\csname REF:#1\endcsname\@empty \def\@currentlabel{#2}\label{#1}% \else \aftergroup\zzapline \fi}#2} ...


10

There's no problem to do this with the datatool package and siunitx as well. Here's your example done in that way: \documentclass{article} \usepackage{datatool} \usepackage{siunitx} \usepackage{booktabs} % for nicer tables \usepackage{caption} % improve caption spacing (among other things) \usepackage{bm} \renewcommand*\dtldisplaystarttab{\toprule} ...


10

The problem lies with the trailing spaces in your CSV currency values. Because of them, the numbers are treated as strings and the internal conversion from currency to decimal that takes place fails. So with the following CSV: a,"$100,090.06","$107,578.03",0.129565278 b,"$267,697.13","$72,463.54",0.087442318 c,"$761,314.81","$192,210.83",0.231820008 some ...


10

When using \DTLforeach with \hline it's generally better to use the following schematic structure which puts the \\ and the \hline at the beginning of each non-initial row instead of at the end of each row. \DTLforeach{<database>}{<assignments>}{% \DTLiffirstrow{}{\\\hline} rest of table with no final \\ } For your second problem, there may ...


10

The example below defines some commands that allow you to add entries to multiple databases. You can then use the example command \xgls instead of \gls and it will index the entries for each of the databases. So if pdf is in the glossary, acronym and index database, \xgls{pdf} will add a location to each database, whereas if html is only in the acronym and ...


10

TeX's registers can be addressed either by name or by number. To keep a track of the numbers allocated to names, it is necessary to have an allocation routine, which \newcount provides an interface for. Thus when you do \newcount\foo you define \foo to mean \count<number>, and mark <number> as 'taken'. If you subsequently do ...


10

\DTLforeach visits the rows one after another. Therefore the row order of the data base matters: \DTLforeach*[\DTLisSubString{#2}{\RowID}]{#1}{% % #2 = list of rowIDs In the following solution I have put the data extraction in a for loop that iterates over the given row IDs. There are many for loops, e.g. LaTeX's \@for. I am using \comma@parse from ...


9

Both datatool and pgfplotstable can do similar things, but datatool is designed as a more general tool and therefore can in principle do more things (e.g. form letters and the like). So if your requirements are simply pretty printing tables directly from CSV files I might prefer pgfplotstables since it is especially designed for that, and if you are ...


9

Maybe you want to give LuaLaTeX a try. It's very easy to write a script to read external files and format LaTeX commands. It is good practice to write the lua functions in a separate file with the extension .lua. For this MWE I use the filecontents environment instead to provide an extra file for the lua script and the datafile. Here is an other example for ...


9

(La)TeX tabulars do not require a predefined number for the rows. For the columns, however, this is required in the general setup. You can combine column specifications that are similar though using a *{<num>}{<col spec>} specification. This would repeat <col spec> a total of <num> times. Therefore, defining \begin{tabular}{ | ...


9

I've just uploaded v2.13 to CTAN. It will probably take a day or so to propagate through the mirrors and distros, but once it's available you can use the code below. The best solution is to only define the database once (before the loop) and clear it each time round the loop. This means that you're not constantly allocating new registers. The new version ...


9

Joseph has explained the reason why the problem arises. Here's a possible workaround. I define a set of macros that set up two pools of token registers and count registers, from which to choose new ones when \DTLdbnewdb is called and that are reinserted in the pool when \DTLdeletedb is issued. One can increase the size of the pool, with the following macros ...


8

When using the babel package with the french option, semicolons (and colons, exclamation marks and question marks) are made active so the spacing around these punctuation symbols can be corrected for the French style of putting space before and after the symbol: "Normal" spacing: French spacing: If you use the semicolon as the field separator in your ...


8

datatool already loads fp which provides \FPround{<out>}{<in>}{<num>}, rounding <in> to <num> decimal places and stores it in <out>. datatool mirrors this with \DTLround (and/or \DTLtrunc if you wish to truncate rather than round): \documentclass{article} \usepackage{datatool,filecontents}% ...


8

I had this problem with datatool not recognising tabs. I believe there is a bug in the definition of \DTLsettabseparator in datatool.sty. \DTLsettabseparator tries to make \DTLsetseparator a tab but fails, but you can override this by making \DTLsetseparator a tab in your document using: \catcode`\^^I=12 % \DTLsetseparator{ }% The gap in { } is a tab.


8

You can set the starting angle of the first segment by the setting start=90. The value is 0 by default. \DTLpiechart{variable=\quantity,outerlabel=\name,start=90,radius=1.8cm,outerratio=1.1}{institute}{% \name=Name,\quantity=Quantity} I have made some other changes too in the settings so that the chart looks more good. \documentclass{beamer} ...


7

Here's a possible solution: \documentclass{article} \usepackage{eso-pic} \usepackage{fancyhdr} \usepackage{blindtext} % just for the example \usepackage[headsep=3cm,top=5cm]{geometry} \usepackage{datatool} % create sample csv file \begin{filecontents*}{test.csv} Id,myauthor,mydate,myaddress 1,Sebastian,12.12.2012,XYZ road,XYZ city 2,Rose,12.12.2013,XYZ ...


7

Not sure about the datatool usage, but if you just want to process a comma separated list I think that package is a lot more powerful than you need. The following plain TeX produces $ tex ll5 This is TeX, Version 3.1415926 (Web2C 2010) (./ll5.tex [ABC, DEF, ABC, MMM, MMM, JHM] -> [ABC,DEF,MMM,JHM] [ABC] -> [ABC] [] -> [] [xx, yyy, xx, yyy, sss] ...


7

I don't know if I understand fully what you mean by "having to pre-define the number of rows" (did you mean to write columns?). As long as you know, for instance, that the table should contain a left-justified header column and n centered data columns -- with all columns separate by vertical lines, according to the example you give -- the following will work ...


7

You can first of all use a macro to hold the name of the .csv file in abc.tex: \documentclass{article} \usepackage{datatool} \begin{document} ... \DTLloaddb[noheader,keys={Temperature,Time,T2G}]{data}{\csvname.csv} ... \end{document} Then you can call xelatex from the command line by saying xelatex -jobname=abc-pqr '\def\csvname{pqr}\input{abc}' ...


7

I checked the datatool manual and found the following note about \DTLnewdbentry (page 32): The value isn’t expanded by default, but you can change this using the declaration: \dtlexpandnewvalue. This can be localised by placing it in a group, or you can switch back using: \dtlnoexpandnewvalue. I simply rewrote \myCom: \newkeycommand{\myCom}[op=1]{% ...


7

\csname is a useful construct for defining a "dynamic" macro name based on some input, but when you're using the same basic structure in different places, you have to make sure the constructed macro names really match up. For instance, comparing this \expandafter\gdef\csname\Dir Color\endcsname{\ExpandedDirColor}% with that ...


7

If you add \pdfcompresslevel=0 To the top of the document then you get filesizes of 3129555 and 13642 with and without hyperref. Looking in the pdf the first obvious difference is 26368 occurrences of the identical line /D [3 0 R /XYZ 88.291 795.961 null] which as far as I know is setting a named destination at those coordinates. That on its own ...


7

As I hinted in a comment, even if Sharelatex allows to use lualatex as compiler for your documents, it does not allow network connections from luatex code. I performed the following test: Wrote the following testing file, which attempts a connection to Google Geocoding API to get a JSON containing geocoding information about the location "1600 Amphitheatre ...



Only top voted, non community-wiki answers of a minimum length are eligible