将文本与制表符对齐并插入图中

align text with tab and insert in figure

我想在 Matlab 的单独子图中添加模型描述。描述是通过读取可以具有不同长度的用户输入数据形成的,我希望它按列对齐显示,例如:

玩家1____Andrew______blue

玩家2____Bob_________green

玩家3____Johnathan___red

(用空格代替“_”)

我不知道该怎么做。 我尝试使用 '\t', 'char(9)';明确指定空格数;并尝试创建一个单元格数组 - 没有任何效果。任何想法为什么以及是否有其他方法可以这样做?非常感谢任何 comments/suggestions 并感谢您的宝贵时间!

clf 
str1=[]; str2=[]; str3=[]; str4=[];
names={'Andrew', 'Bob', 'Johnathan'};
colorsorder={'blue', 'green', 'red'};

figure(1)
d1=subplot(2,2,1);
for i=1:3
    newstr=['player ', num2str(i), '\t', char(names(i)), '\t', ...
            'color= ', char(colorsorder(i)), ' \n'];
    str1=strcat(str1, newstr);
end
y=ylim(d1);
t=text(0, y(2), sprintf(str1), 'Parent', d1);
set(t, 'FontSize', 15)
axis off

d2=subplot(2,2,2);
for i=1:3
    newstr=['player ', num2str(i), char(9) , char(names(i)), char(9), ...
            'color= ', char(colorsorder(i)), ' \n'];
    str2=strcat(str2, newstr);
end
y=ylim(d2);
t=text(0, y(2), sprintf(str2), 'Parent', d2);
set(t, 'FontSize', 15)
axis off

d3=subplot(2,2,3);
tab=15;
for i=1:3
    newstr=['player ', num2str(i), blanks(5), char(names(i)),...
             blanks(tab-length(char(names(i)))),...
            'color= ', char(colorsorder(i)), ' \n'];
    str3=strcat(str3, newstr);
end
y=ylim(d3);
t=text(0, y(2), sprintf(str3), 'Parent', d3);
set(t, 'FontSize', 15)
axis off

d4=subplot(2,2,4);
dtable=cell(3, 3);
for i=1:3
    dtable(i, 1)={['player ', num2str(i)]};
    dtable(i, 2)={char(names(i))};
    dtable(i, 3)={['color ',char(colorsorder(i))]};
    str4=strcat(str4, strjoin(dtable(i,:), '\t'), '\n');
end
y=ylim(d4);
t=text(0, y(2), sprintf(str4), 'Parent', d4);
set(t, 'FontSize', 15)
axis off

Matlab tex 解释器有制表符 (\t) 问题。我会选择乳胶解释器,并使用 table 进行正确对齐。看下面的例子:

clf 
str1=[]; str2=[]; str3=[]; str4=[];
names={'Andrew', 'Bob', 'Johnathan'};
colorsorder={'blue', 'green', 'red'};

figM = figure(1);
d1=subplot(2,2,1);

latexString = '$$\begin{tabular}{lll}';
for i=1:3
    latexString = [latexString sprintf('player %s & %s & color= %s\\ ', num2str(i), names{i}, colorsorder{i})];  
end
latexString = [latexString '\end{tabular}$$'];

axis off

text('String',latexString,...
'Interpreter','latex',... 
'Position',[.5 .5],...
'FontSize',16)