How do I draw an en dash in MATLAB using the TeX interpreter?

59 ビュー (過去 30 日間)
Doug Hull
Doug Hull 2011 年 1 月 12 日
コメント済み: Walter Roberson 2017 年 2 月 24 日
I am trying to write text within a figure, and I need to be able to differentiate between a hyphen and an en dash (hyphen being slightly shorter).

採用された回答

Doug Hull
Doug Hull 2011 年 1 月 12 日
You can use the ASCII codes for the specific type of dash you would like to display in the call to the TEXT function. For example,
plot(1:10); % This will draw a hyphen
h1 = text(2,2,['Test-example']); % This will draw an en dash
h1 = text(2,4,['Test' char(8211) 'example']); % This will draw an em dash
h1 = text(2,6,['Test' char(8212) 'example']);
Please refer to the following page to see numeric codes for the common dashes:
  2 件のコメント
Nathan
Nathan 2017 年 2 月 24 日
編集済み: Nathan 2017 年 2 月 24 日
Doug,
Thanks for pointing this method out. I'm using R2014a on a mac workbook pro running 10.9.5. This method does not work in that it fails to produce the desired en dash. It also fails to produce an error code as well. Here is the command I would like to add an en dash to:
text(0.265,0.25,'\leftarrow NS XCPC','FontSize',28)
My goal is to produce an en dash between the N and S.
I also tried Andrew Newell's method:
h1 = text(2,4,'en--dash','Interpreter','latex');
although, this method works just fine, the latex interpreter does not know how to process the
\leftarrow
MatLab command.
Any suggestions on how to accomplish both activities (en dash and left arrow) at the same time?
Walter Roberson
Walter Roberson 2017 年 2 月 24 日
I just tried in R2014a on MacBook Pro with El Capitan.
text(2,3,'\leftarrow N--S XCPC')
looks to work for me.

サインインしてコメントする。

その他の回答 (1 件)

Andrew Newell
Andrew Newell 2011 年 1 月 26 日
If you use the latex interpreter, it's really simple:
plot(1:10);
h1 = text(2,2,'Hy-phen','Interpreter','latex');
h1 = text(2,4,'en--dash','Interpreter','latex');
h1 = text(2,6,'em---dash','Interpreter','latex');

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by