How to write big fraction in texts

Is it in Matlab possible to plot a fraction in text which keeps the same text size. That is not reducing the text size inside the \frac enviroment?
In LaTeX you have the command \dfrac{a}{b} but this command doesn't work in Matlab using the LaTeX interpreter?
figure (1)
plot(Bq,d);
title('Pore Pressure Ratio');
xlabel('B_q [-]');
ylabel('Depth [m]');
text(0.8,-2.8,'$B_q = \frac{\Delta u}{q_t-\sigma_{v0}}$','interpreter','latex','EdgeColor','k'); % the text within the frac is reduced here :(
set (gca,'Ydir','reverse');
grid on;

8 Kommentare

Sarah Crimi
Sarah Crimi am 7 Feb. 2019
title('$$B_q = \frac{\Delta u}{q_t-\sigma_{v0}}$$','interpreter','latex')
Adam Danz
Adam Danz am 7 Feb. 2019
A visual always helps. Here's the result of the code (with fake data). So, the problem is that the font size of the fraction is reduced and you'd like it to be the same font size as the text on the left of the equal sign?
190207 115100-Figure 1.jpg
Marius Hammer
Marius Hammer am 8 Feb. 2019
Yes this is correct. So instead of the fraction looking like the left one below, I want it to look like the right one, so that there is no relative fontsize different
Unavngivet.png
Adam Danz
Adam Danz am 8 Feb. 2019
What if you treat the left and right sides of the equal sign as separate texts and increase the font size on the right so that it's slightly larger than on the left?
Marius Hammer
Marius Hammer am 9 Feb. 2019
Bearbeitet: Marius Hammer am 9 Feb. 2019
Didn't quite think of that in the beginning. It works, although being an alternative and a little clumsy way, especially if also using an 'EdgeColor' where I have to use a spacing over the text outside the fraction for the border to be around the entire text and not only the fraction.
It is however a bit sad that the LaTeX command \dfrac{a}{b} doesn't work in Matlab which does exactly this, forcing the fraction to be shown in full size (display mode).
% Equation in one text box
text(0.6,-2.8,'$B_q = \frac{\Delta u}{q_t-\sigma_{v0}}$','interpreter','latex','FontSize',12,'EdgeColor','k');
% Equation text box splitted to avoid relative fontsize
text(1.1,-2.8,'$B_q = $','interpreter','latex','FontSize',12);
text(1.1,-2.8,'$\hspace{2em}\frac{\Delta u}{q_t-\sigma_{v0}}$','interpreter','latex','FontSize',16,'EdgeColor','k');
Walter Roberson
Walter Roberson am 9 Feb. 2019
I see Latex fontsize reference but nothing there seems to work except that MATLAB does not reject \fontsize but also does not appear to act on it.
Star Strider
Star Strider am 9 Feb. 2019
I am not certain if the text call 'FontSize' name-value pair scales the font or scales the entire text object. It definitely has some effect.
Nevrtheless, there appear to be some problems with the LaTeX interpreter as MATLAB uses it.
Walter Roberson
Walter Roberson am 10 Feb. 2019
For example '$\fontsize{50}{60}B_q$' is not rejected by the interpreter, but makes no change to the output -- not even to drop something in that is then clipped. The output is as-if the \fontsize were not present in each case I tested.
This is not the same as the 'FontSize' option to text()

Melden Sie sich an, um zu kommentieren.

Antworten (1)

matt majic
matt majic am 6 Okt. 2021

2 Stimmen

Yes. Simply enclose the latex formula in double dollar signs $$.

1 Kommentar

Could you give an explanation of the differences between enclosing LaTex forumale in single and double dollar signs?

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by