Run it with xelatex
or latex=>dvips=>ps2pdf
\documentclass{article}
\usepackage{array,ragged2e,pst-node,pst-dbicons}
\newcolumntype{C}[1]{>{\Centering}p{#1}}
\def\Tab#1{\tabular{C{3cm}}\rule[-5mm]{0pt}{1cm}#1\\\hline
~\\\hline~\endtabular}
\seticonparams{entity}{shadow,fillcolor=black!20,fillstyle=solid,framesep=0pt}
\begin{document}
\entity{students}[\Tab{Students}]\hspace{2.5cm}
\entity{courses}[\Tab{Courses}]
\ncline[arrowscale=2]{->}{students}{courses}
\naput[npos=0.1]{1}\naput{take}\naput[npos=0.85]{1..*}
\end{document}
Let's assume you want this output:
If you use LuaTeX, the most innovative way is to include the luasql bindings in your program.
First create a simple database (createdb.txt
):
CREATE TABLE people(
name varchar(50),
email varchar(50)
);
INSERT INTO "people" VALUES('Jose das Couves','jose@couves.com');
INSERT INTO "people" VALUES('Manoel Joaquim','manoel.joaquim@cafundo.com');
INSERT INTO "people" VALUES('Maria das Dores','maria@dores.com');
and fill it with sqlite3 luasql-test < createdb.txt
The next step is to create a simple LuaLaTeX document and read the file into the table:
\documentclass{article}
\usepackage{luacode,booktabs}
\begin{document}
\begin{luacode*}
require("luasql.sqlite3")
env = assert (luasql.sqlite3())
-- connect to data source
con = assert (env:connect("luasql-test"))
-- retrieve a cursor
cur = assert (con:execute"SELECT name, email from people")
-- print all rows, the rows will be indexed by field names
row = cur:fetch ({}, "a")
tex.sprint([[\begin{tabular}{@{}ll@{}}\toprule]])
tex.sprint([[Name & email \\\midrule]])
while row do
tex.sprint(-2,row.name)
tex.sprint("&")
tex.sprint(-2, row.email)
tex.sprint("\\\\")
-- reusing the table of results
row = cur:fetch (row, "a")
end
tex.sprint([[\bottomrule\end{tabular}]])
-- close everything
cur:close()
con:close()
env:close()
\end{luacode*}
\end{document}
(The example is taken from the luasql home page.)
I have skipped the worst part: compiling and installing. This is highly system dependent, but I will list some steps/pitfalls.
- On MacOS X, you can't use the
sqlite3.so
from luasql directly, because the luatex
binary misses some symbols. So you need to compile your own non-stripped luatex binary (./build.sh --nostrip
) and use that instead. It needs to be placed at the "original" version in the tex tree. If you have done that, you can use sqlite3.so
from the luasql project. The same might be true on other unix systems. See the entry 666 in the bug tracker.
- Create a directory called
luasql
in your document directory and place the generated library there.
- You need LuaTeX version > 0.46.0. Therefore texlive 2011 might be the best choice.
- I have downloaded the source distribution of luasql and compiled it myself. I don't know if the luarocks based installation can be used as well (probably it can).
Best Answer
Here's a solution based on Arianna's link :
Which gives :