function export_uniform_plot(fig,filename, varargin)
% EXPORT_UNIFORM_PLOT Save the current MATLAB figure with consistent layout for LaTeX.
%
% Usage:
%   export_uniform_plot('fig_name');
%
% Optional name-value arguments:
%   'Width'      - in pixels (default: 600)
%   'Height'     - in pixels (default: 400)
%   'FontSize'   - in pt (default: 10)
%   'FontName'   - default: 'Times New Roman'
%   'Format'     - 'pdf' (default), 'eps', 'svg'

% Parse options
p = inputParser;
addParameter(p, 'Width', 600);
addParameter(p, 'Height', 400);
addParameter(p, 'FontSize', 10);
addParameter(p, 'FontName', 'Times New Roman');
addParameter(p, 'Format', 'pdf');
parse(p, varargin{:});
opts = p.Results;

% Set figure size
%fig = gcf;
set(fig, 'Units', 'pixels', 'Position', [100 100 opts.Width opts.Height]);

% Apply consistent axis formatting
ax = findall(fig, 'Type', 'axes');
for a = ax'
    set(a, 'Units', 'normalized', ...
        'Position', [0.13 0.15 0.75 0.75], ... % fixed axis area
        'FontSize', opts.FontSize, ...
        'TickLength', [0.01 0.01], ...
        'Box', 'off');%'FontName', opts.FontName, ...

    % Optional: fix number format
    xtickformat(a, '%.2f');
    ytickformat(a, '%.2f');
end

% Tighten layout (optional, but safe if used after fixing Position)
try
    tightfig;
catch
    warning('tightfig not available. Consider installing from FileExchange.');
end

% Export
switch lower(opts.Format)
    case 'pdf'
        exportgraphics(fig, [filename '.pdf'], 'ContentType', 'vector');
    case 'eps'
        print(fig, filename, '-depsc', '-r300');
    case 'svg'
        exportgraphics(fig, [filename '.svg'], 'ContentType', 'vector');
    otherwise
        error('Unsupported format.');
end

fprintf('Saved figure: %s.%s\n', filename, opts.Format);
end
