diff --git a/matlab/reports/@graph/write.m b/matlab/reports/@graph/write.m
index 7fee076f3a3c84cf47bc007de12cf610e3d7142d..4c4936672b580367a79aa7f5ac06a990b6c5f228 100644
--- a/matlab/reports/@graph/write.m
+++ b/matlab/reports/@graph/write.m
@@ -1,10 +1,14 @@
-function o = write(o, fid)
-%function o = write(o, fid)
+function o = write(o, fid, pg, sec, row, col)
+%function o = write(o, fid, pg, sec, row, col)
 % Write a Graph object
 %
 % INPUTS
 %   o   [graph]   graph object
 %   fid [integer] file id
+%   pg  [integer] this page number
+%   sec [integer] this section number
+%   row [integer] this row number
+%   col [integer] this col number
 %
 % OUTPUTS
 %   o   [graph] graph object
@@ -30,6 +34,6 @@ function o = write(o, fid)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 assert(fid ~= -1);
-o = writeGraphFile(o);
+o = writeGraphFile(o, pg, sec, row, col);
 fprintf(fid, '\\input{%s}', o.figname);
 end
\ No newline at end of file
diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m
index d130f8d613f9827aca920cd6a3f6a9a51c031a23..57528abf768a80229ea04630dcac9fe4e2df7b16 100644
--- a/matlab/reports/@graph/writeGraphFile.m
+++ b/matlab/reports/@graph/writeGraphFile.m
@@ -1,9 +1,13 @@
-function o = writeGraphFile(o)
-%function o = writeGraphFile(o)
+function o = writeGraphFile(o, pg, sec, row, col)
+%function o = writeGraphFile(o, pg, sec, row, col)
 % Write the tikz file that contains the graph
 %
 % INPUTS
-%   o   [graph] graph object
+%   o   [graph]   graph object
+%   pg  [integer] this page number
+%   sec [integer] this section number
+%   row [integer] this row number
+%   col [integer] this col number
 %
 % OUTPUTS
 %   o   [graph] graph object
@@ -35,11 +39,7 @@ if ne < 1
 end
 
 if isempty(o.figname)
-    [junk, tn] = fileparts(tempname);
-    if strcmp(computer, 'PCWIN') || strcmp(computer, 'PCWIN64')
-        tn = strrep(tn, '_', '-');
-    end
-    o.figname = [o.figDirName '/' tn '.tex'];
+    o.figname = sprintf('%s/pg%d_sec%d_row%d_col%d.tex', o.figDirName, pg, sec, row, col);
 end
 
 [fid, msg] = fopen(o.figname, 'w');
diff --git a/matlab/reports/@page/write.m b/matlab/reports/@page/write.m
index c8bd3c04021fa7d47a1cf28f084a9e05db483f83..274cf3c2c05ac7f493e99036ea2aa6f580c3c993 100644
--- a/matlab/reports/@page/write.m
+++ b/matlab/reports/@page/write.m
@@ -1,10 +1,11 @@
-function o = write(o, fid)
-%function o = write(o, fid)
+function o = write(o, fid, pg)
+%function o = write(o, fid, pg)
 % Write a Page object
 %
 % INPUTS
 %   o              [page]     page object
 %   fid            [integer]  file id
+%   pg             [integer]  this page number
 %
 % OUTPUTS
 %   o              [page]     page object
@@ -48,7 +49,7 @@ end
 
 nps = length(o.sections);
 for i=1:nps
-    o.sections{i}.write(fid);
+    o.sections{i}.write(fid, pg, i);
 end
 
 if strcmpi(o.orientation, 'landscape')
diff --git a/matlab/reports/@report/write.m b/matlab/reports/@report/write.m
index fd6efceabd18bc52585b7efacc45d2d5b1d70fa2..c2016f86228e491020b854d00df22f1c36248071 100644
--- a/matlab/reports/@report/write.m
+++ b/matlab/reports/@report/write.m
@@ -80,7 +80,7 @@ fprintf(fid, '\\centering\n');
 nps = length(o.pages);
 for i=1:nps
     fprintf(1, 'Writing Page: %d\n', i);
-    o.pages{i}.write(fid);
+    o.pages{i}.write(fid, i);
 end
 
 fprintf(fid, '\\end{document}\n');
diff --git a/matlab/reports/@report_table/write.m b/matlab/reports/@report_table/write.m
index 4460e5d3f2e497826474fff332c69e960fa722ea..5a97362f35992df40d4e06a8f2fee74b13d35abf 100644
--- a/matlab/reports/@report_table/write.m
+++ b/matlab/reports/@report_table/write.m
@@ -1,5 +1,5 @@
-function o = write(o, fid)
-%function o = write(o, fid)
+function o = write(o, fid, pg, sec, row, col)
+%function o = write(o, fid, pg, sec, row, col)
 % Write a Report_Table object
 %
 % INPUTS
diff --git a/matlab/reports/@section/write.m b/matlab/reports/@section/write.m
index 4055dd6f7256cff366fe1eb82a2293aff4ea167a..888e7a9f0233addc7cdd4b03893abe1832a894e8 100644
--- a/matlab/reports/@section/write.m
+++ b/matlab/reports/@section/write.m
@@ -1,10 +1,12 @@
-function o = write(o, fid)
-%function o = write(o, fid)
+function o = write(o, fid, pg, sec)
+%function o = write(o, fid, pg, sec)
 % Write Section object
 %
 % INPUTS
 %   o         [section] section object
 %   fid       [integer] file id
+%   pg        [integer] this page number
+%   sec       [integer] this section number
 %
 % OUTPUTS
 %   o         [section] section object
@@ -48,20 +50,24 @@ end
 fprintf(fid, '}\n');
 ne = numElements(o);
 nlcounter = 0;
+row = 1;
+col = 1;
 for i=1:ne
     if isa(o.elements{i}, 'vspace')
-        assert(rem(nlcounter, o.cols) == 0, ['@section.write: must place ' ...
+        assert(col == o.cols, ['@section.write: must place ' ...
                             'vspace command after a linebreak in the table ' ...
                             'or series of charts']);
         o.elements{i}.write(fid);
         fprintf(fid, '\\\\\n');
     else
-        o.elements{i}.write(fid);
-        nlcounter = nlcounter + 1;
-        if rem(nlcounter, o.cols)
+        o.elements{i}.write(fid, pg, sec, row, col);
+        if col ~= o.cols
             fprintf(fid, ' & ');
+            col = col + 1;
         else
             fprintf(fid, '\\\\\n');
+            row = row + 1;
+            col = 1;
         end
     end
 end