Pretty Print and table

Hi scilab Team, i have experimented with tables and prettyprint. and have seen, that scilab lates not recognizes table. Would be this not be a nice feature for upcomming milestone?
An i also have seen, that when you launch JCEF, the whole scilab gui changes to JCEF mode by so.

Hello Pascal,

Did you have a look to the following post (don’t pay attention to the title, it is about LaTeX export of tables): Export a table to a file - #3 by mottelet ? You should be able to reuse the code to generate LaTeX markup for an arbitrary table.

S.

sorry, no, i did not seen it, it is also a possibility and feasibility, but not so elegant.
And for the other point, has someone noticed?

Do you have a more elegant solution :rofl:? Moreover, if the feature has to be coded in prettyprint() I am affraid that the code will be very similar. Missing features have to be coded, that’s the law !

S.

1 Like

Yeah, but as lazy enduser, it would be nice that table can by simple prettyprint be in Latex :slight_smile:

Can you test the following code:

function str = table2latex(t)
    [_,m] = size(t);
    head = strcat(t.props.VariableNames," & ") + " \\ "
    data = strcat(strcat(string(t)," & ","c")," \\ ")
    str = [ sprintf("\\begin{tabular}{%s}",strcat("r"(ones(1,m)),"|"))
        head; "\hline"; data; "\end{tabular}" ];
    str = strcat(str," ");
endfunction

after defining the function table2latex, the Scilab function prettyprint should work for tables (default LateX mode):

t = table(rand(5,3,"normal"), ...
    "VariableNames",["var1Name","var2Name","myLongVarName"])
pp = prettyprint(t)
titlepage(pp)
gce().interpreter = "latex"

S.

2 Likes


zhat works for the example well, andhas some box arround, but with my exapmle not quite. but i will look further when i have time

The box is made by titlepage, use the latex code as you want…

S.

OK, i will try this, thanks


doesn’t quite work on every occasion, must look why. maybe because my table are full in string or struct2table is not quite the same as table?

M.f.G. Pascal

Do you have an example ?

WI.school=[“BHF”,“FFHS”,“FHNW”,“HEIG-VD”,“HSLU”,“SUPSI”,“OST”,“ZHAW”];
WI.place=[“Quellgasse 21 2501 Biel”,“Schinerstrasse 18 3900 Brig”,“Bahnhofstrasse 6 5210 Windisch”,“Route de Cheseaux 1, 1400 Yverdon-les-Bains”,“Technikumstrasse 21 6048 Horw”,“Via la Santa 1 6962 Lugano-Viganello”,“Rosenbergstrasse 59 9000 St.Gallen”,“Technikumstrasse 9 8400 Winterthur”];
WI.teacher=[“Prof. Dr. Stefan Grösser”,“CAO Simon Ruff”,“Prof. Jörg Lageman”,“Prof. Jean-Michel Schulz”,“Prof. Thomas Schwank”,“Prof. Paolo Pedrazzoli”,“Prof. Sonderegger Urs”,“Prof. Dr. Richard Bödi”];
Table_WI=struct2table(WI);

t=table2latex(Table_WI)
pp = prettyprint(t)
titlepage(pp)
gce().interpreter = “latex”

this is my example.

m.f.g. Pascal

i have seen, that discourse mismatches the “” scilab string function.
Test.sci (692 Bytes)

Please use code blocks, otherwise this is very complicated to copy-paste the code you are posting (see https://scilab.discourse.group/t/welcome-to-the-scilab-discourse-forum).

Likely, you didn’t understand the different mechanisms in place: you don’t have to call yourself table2latex (it is automatically called by prettyprint). So the whole code of your example should be:

function str = table2latex(t)
    [_,m] = size(t);
    head = strcat(t.props.VariableNames," & ") + " \\ "
    data = strcat(strcat(string(t)," & ","c")," \\ ")
    str = [ sprintf("\\begin{tabular}{%s}",strcat("r"(ones(1,m)),"|"))
        head; "\hline"; data; "\end{tabular}" ];
    str = strcat(str," ");
endfunction

WI.school=["BHF","FFHS","FHNW","HEIG-VD","HSLU","SUPSI","OST","ZHAW"];
WI.place=["Quellgasse 21 2501 Biel","Schinerstrasse 18 3900 Brig","Bahnhofstrasse 6 5210 Windisch","Route de Cheseaux 1, 1400 Yverdon-les-Bains","Technikumstrasse 21 6048 Horw","Via la Santa 1 6962 Lugano-Viganello","Rosenbergstrasse 59 9000 St.Gallen","Technikumstrasse 9 8400 Winterthur"];
WI.teacher=["Prof. Dr. Stefan Grösser","CAO Simon Ruff","Prof. Jörg Lageman","Prof. Jean-Michel Schulz","Prof. Thomas Schwank","Prof. Paolo Pedrazzoli","Prof. Sonderegger Urs","Prof. Dr. Richard Bödi"];
Table_WI=struct2table(WI);

pp = prettyprint(Table_WI)
titlepage(pp)
gce().interpreter = "latex"

The alignment of strings within the columns can be changed, e.g. if you want to center strings just change "r" line 6 of table2latex by "c" (center) or "l" (left).

stuff

Thanks, yes this works. Although the spaces between are not, but i can work around it. many thanks. :slight_smile:

You can tune almost everything from the LaTeX side.

1 Like