我在文檔中使用全域預設變數\figwidth
作為圖形寬度和高度。\figheight
這些是由我的文件標題中的以下程式碼定義的:
乳膠
\newcommand{\figwidth}{0.8\textwidth} % sets \figwidth, which can be used as default width for figures
\newcommand{\figheight}{\figwidth/1.618} % sets \figheight, which can be used as default heigth for figures
在Matlab中,我將上述變數傳遞給matlab2tikz.m,如下所示:
MATLAB
x = linspace(0,5,500);
y = sin(x);
figure
plot(x,y)
title('Sine Plot')
cleanfigure;
matlab2tikz('width','\figwidth','height','\figheight');
然而,matlab2tikz 內部似乎發生了一些魔法,因為它應用了係數 0.95092到我預定義的\figwidth
乳膠
\begin{tikzpicture}
\begin{axis}[%
width=0.95092\figwidth,
height=\figheight,
at={(0\figwidth,0\figheight)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=5,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=-1,
ymax=1,
title={Sine Plot}
]
\addplot [color=blue,solid,forget plot]
table[row sep=crcr]{%
0 0\\
0.0100200400801603 0.010019872410322\\
0.0200400801603206 0.020038738821815\\
0.030060120240481 0.0300555933366527\\
//..... many more entries in table .....
4.98997995991984 -0.961718395396395\\
5 -0.958924274663138\\
};
\end{axis}
\end{tikzpicture}%
我目前的解決方法是在 Matlab 程式碼中加入 0:
MATLAB
matlab2tikz('width','0\figwidth','height','\figheight');
產生:
乳膠
width=0\figwidth,
\figwidth
即考慮我最初的讀取定義時的最終結果
width=00.8\textwidth, % = 0\figwidth
目前來說這很好,但在某些情況下可能會破壞程式碼,這些情況不涉及我對寬度變數的初始定義。例如
\newcommand{\figwidth}{\textwidth}
將產生零圖形寬度:
width=0\textwidth, % = 0\figwidth = 0
我已經搜尋了 matlab2tikz 套件的 src 資料夾中包含的所有 *.m 檔案來尋找此因素,但在程式碼中沒有找到結果。
TL:博士;有誰知道是什麼導致了神奇因子 0.95092 以及如何避免它?預先非常感謝您的幫忙!
答案1
相同的帖子在 Github 上得到了答案。回覆請參閱 Github 連結。