From 9b8605896b960ab99e8f608f1f251e389042c558 Mon Sep 17 00:00:00 2001 From: robineriksson Date: Wed, 20 Apr 2022 14:15:26 +0200 Subject: [PATCH] added hline on extra lines and caption on top --- Utils/arr2latex.m | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Utils/arr2latex.m b/Utils/arr2latex.m index 97ed042..6cb9357 100755 --- a/Utils/arr2latex.m +++ b/Utils/arr2latex.m @@ -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; ... @@ -82,6 +85,7 @@ end fmt = frepmat(fmt,rep); + % parse options opts = struct('collabel','', ... 'rowlabel','', ... @@ -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') @@ -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']; @@ -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)]) ... @@ -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 @@ -174,8 +185,6 @@ % ...and the end! S = [S ... '\\end{tabular}\n' ... - opts.caption ... - opts.label ... '\\end{table}']; % let sprintf do the rest @@ -229,4 +238,4 @@ else s = sprintf(['%' f],t); end -%-------------------------------------------------------------------------- +%-------------------------------------------------------------------------- \ No newline at end of file