Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Utils/arr2latex.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
%
% pos String {'htp'} The position of the table.
%
% h2line Integer {4} Insert an extra \hline between
% major rows.
%
% Examples:
% % a small table of the BesselJ-function
% A = [0 1:5; ...
Expand Down Expand Up @@ -82,6 +85,7 @@
end
fmt = frepmat(fmt,rep);


% parse options
opts = struct('collabel','', ...
'rowlabel','', ...
Expand All @@ -94,6 +98,7 @@
'centering','on', ...
'colspec',['|' frepmat('c|',[1 size(T,2)])], ...
'label','', ...
'h2line',[], ...
'pos','htp');
[opts,got] = parseopts(opts,varargin);
if strcmpi(opts.hline,'on')
Expand All @@ -117,9 +122,12 @@
opts.caption = ['\\caption{' l_string(opts.caption) '}\n'];
end


% the beginning...
S = ['\\begin{table}[' opts.pos ']\n' ...
opts.centering ...
opts.caption ...
opts.label ...
'\\begin{tabular}{' opts.colspec '}\n' ...
'\t\\hline\n'];

Expand All @@ -144,7 +152,7 @@
for j = 1:size(T,2)
ss = l_format(fmt{i,j},T(i,j));

% signs for infinity and NaN's, if any -- try to keep the tabs
% signs for infinity and NaN's, if any -- try to keep the tabs
% of the table whenever possible
if ~isempty(opts.posinf) && T(i,j) == Inf
ss = [frepmat(' ',[1 max(size(ss,2)-size(opts.posinf,2),0)]) ...
Expand All @@ -165,6 +173,9 @@

% new row
s = [s '\t\\\\\n' opts.hline];
if ~isempty(opts.h2line) && ~mod(i, opts.h2line) && i~=size(T,1)
s = [s '\t\\hline\n' opts.hline];
end
S = [S s];
end

Expand All @@ -174,8 +185,6 @@
% ...and the end!
S = [S ...
'\\end{tabular}\n' ...
opts.caption ...
opts.label ...
'\\end{table}'];

% let sprintf do the rest
Expand Down Expand Up @@ -229,4 +238,4 @@
else
s = sprintf(['%' f],t);
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------