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

15 Ansichten (letzte 30 Tage)
Doug Hull
Doug Hull am 12 Jan. 2011
Kommentiert: Walter Roberson am 24 Feb. 2017
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).

Akzeptierte Antwort

Doug Hull
Doug Hull am 12 Jan. 2011
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 Kommentare
Nathan
Nathan am 24 Feb. 2017
Bearbeitet: Nathan am 24 Feb. 2017
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 am 24 Feb. 2017
I just tried in R2014a on MacBook Pro with El Capitan.
text(2,3,'\leftarrow N--S XCPC')
looks to work for me.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Andrew Newell
Andrew Newell am 26 Jan. 2011
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');

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by