Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

How to center text in Latex and adjust line spacing?

Asked by Frits

Frits (view profile)

on 28 Jun 2011

LS,

I would like to center a formula in Latex and increase the line space. The code that I currently use is:

text(0.5, 0.5, ...
   'string', {'$$a=$$', '$$\ \frac{bbb}{ccc}$$'}, ...
   'interpreter', 'latex');

Hopefully somebody can help me with this. Thanks a lot in advance.

Best,

Frits

0 Comments

Frits

Frits (view profile)

Products

1 Answer

Answer by Patrick Kalita

Patrick Kalita (view profile)

on 28 Jun 2011

It will probably be easiest to do this by making two separate text objects. When you tell the text object to use the LaTeX interpreter, MATLAB will just hand off the string to the LaTeX system and let it control all the layout (like centering and line spacing). And getting LaTeX to do exactly what you want can get awfully complicated. So I would just make two text objects. The relative positions would control the line space, and the HorizontalAlignment controls the centering:

text(0.5, 0.5, '$$a=$$', 'HorizontalAlignment', 'center', 'interpreter', 'latex');
text(0.5, 0.4, '$$\ \frac{bbb}{ccccccc}$$', 'HorizontalAlignment', 'center', 'interpreter', 'latex');

0 Comments

Patrick Kalita

Patrick Kalita (view profile)

Contact us