Given ist following legend:
legend('Group 6 MHz \newline{\bff_1} \newline2f_2-f_3 \newlinef_2+f_3-f_4 ', ...
'\newlineGroup7.3 MHz \newline{\bff_2} \newline2f_3-f_4 \newlinef_1+f_3-f_2 \newlinef_1+f_4-f_3 ', ...
'\newlineGroup8.7 MHz \newline{\bff_3} \newline2f_2-f_1 \newlinef_2+f_4-f_3 \newlinef_1+f_4-f_2 ', ...
'\newlineGroup10 MHz \newline{\bff_4} \newline2f_3-f_2 \newlinef_2+f_3-f_1 ','location','northeastoutside')
A total of four graphs with corresponding sub-labels are to be shown here. I want the first line (Group 6 MHz, Group7.3 MHz ...) to be underlined. Does somebody has any idea?
Many thanks!

 採用された回答

madhan ravi
madhan ravi 2020 年 6 月 28 日

0 投票

legend(' $\underline{Mepe}$ ','interpreter','latex')

8 件のコメント

Mepe
Mepe 2020 年 6 月 29 日
Many thanks!
but how do I get that integrated with the other legend so that it looks like this?
Walter Roberson
Walter Roberson 2020 年 6 月 29 日
編集済み: Walter Roberson 2020 年 6 月 29 日
legend( {'$\underline{Group 6 MHz} \newline{\bff_1} \newline{2f_2-f_3} \newline{f_2+f_3-f_4} $', ...
'$\underline{Group7.3 MHz} \newline{\bff_2} \newline{2f_3-f_4} \newline{f_1+f_3-f_2} \newline{f_1+f_4-f_3} $', ...
'$\underline{Group8.7 MHz} \newline{\bff_3} \newline{2f_2-f_1} \newline{f_2+f_4-f_3} \newline{f_1+f_4-f_2} $', ...
'$\newline{Group10 MHz} \newline{\bff_4} \newline{2f_3-f_2} \newline{f_2+f_3-f_1} $'}, ...
'location', 'northeastoutside', 'interpreter', 'latex')
Mepe
Mepe 2020 年 6 月 29 日
Thanks Walter,
Unfortunately, the following picture emerges:
Any idea?
Walter Roberson
Walter Roberson 2020 年 6 月 29 日
Darn, I could not seem to get anything working.
But looking around, it appears that line breaks in math mode is a difficult topic in tex and latex. ams-math package apparently helps some, but you cannot use amsmath in MATLAB legends :(
madhan ravi
madhan ravi 2020 年 6 月 29 日
Yes completely agree, such a simple task is really complex. Will MathWorks enhance these features in the future :( ?
Mepe
Mepe 2020 年 6 月 29 日
Ok, no problem. Thanks for your efforts!
Walter Roberson
Walter Roberson 2020 年 6 月 29 日
I do not understand why Mathworks does not enable \usepackage .
The only thing I have been able to come up with is that perhaps adding packages would make it more difficult to figure out the rendered size of items in order to know how to space text and ticks and legend entries.
madhan ravi
madhan ravi 2020 年 6 月 29 日
Very true perspective.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 7 月 4 日

2 投票

shows the latex code example
\left [\begin {array}{ccc} 1&2&3\\\noalign{\medskip}4&5&6\\\noalign{\medskip}7&8&9\end {array}\right ]
and that works in MATLAB:
plot(rand(1,5));
h = legend('$\left [\begin {array}{ccc} 1&2&3\\\noalign{\medskip}4&5&6\\\noalign{\medskip}7&8&9\end {array}\right ]$', 'interpreter','latex')
So...
S = { '$\begin{array}{l}\underline{Group 6 MHz}\\{\medskip}\bf{f_1}\\{\medskip}2f_2-f_3\\{\medskip}f_2+f_3-f_4\end {array}$', ...
'$\begin{array}{l}\underline{Group7.3 MHz}\\{\medskip}\bf{f_2}{\medskip}2f_3-f_4\\{\medskip}f_1+f_3-f_2\\{\medskip}f_1+f_4-f_3\end {array}$', ...
'$\begin{array}{l}\underline{Group8.7 MHz}\\{\medskip}\bf{f_3}\\{\medskip}2f_2-f_1\\{\medskip}f_2+f_4-f_3\\{\medskip}f_1+f_4-f_2\end {array}$', ...
'$\begin{array}{l}\underline{Group10 MHz}\\{\medskip}\bf{f_4}\\{\medskip}2f_3-f_2\\{\medskip}f_2+f_3-f_1\end {array}$' };
legend(S, 'location', 'northeastoutside', 'interpreter', 'latex')
You will want to work on the vertical spacing a bit.

3 件のコメント

madhan ravi
madhan ravi 2020 年 7 月 4 日
編集済み: madhan ravi 2020 年 7 月 4 日
I am pretty sure I tried with array but never seemed to get it right, but turns out arrays should be used for EACH legend entries, thanks sir Walter!
Walter Roberson
Walter Roberson 2020 年 7 月 4 日
I tried with array myself, but I could not get it to work before. I think the major part I was missing was the column alignment information immediately after the \begin{array}
madhan ravi
madhan ravi 2020 年 7 月 4 日
Aha

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

カテゴリ

質問済み:

2020 年 6 月 28 日

コメント済み:

2020 年 7 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by