Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global width variable scaled by factor 0.95092 #672

Closed
Jay-At-Play opened this issue May 26, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@Jay-At-Play
Copy link

commented May 26, 2015

I use global default variables \figwidth for figure width and \figheight for height in my document.

These are defined by the following code in my document header:

Latex

\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

In Matlab, I pass the aforementioned variables to matlab2tikz.m as shown below:

Matlab

x = linspace(0,5,500);
y = sin(x);

figure
plot(x,y)
title('Sine Plot')

cleanfigure;
matlab2tikz('width','\figwidth','height','\figheight');

However there seems to be some magic happening inside matlab2tikz, as it applies the factor 0.95092 to my predefined \figwidth

Latex

\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}%

My current workaround is adding a 0 in the Matlab code:

Matlab

matlab2tikz('width','0\figwidth','height','\figheight');

which yields:

Latex

width=0\figwidth,

i.e. the end result when considering my initial definition of \figwidth reads

width=00.8\textwidth,   % = 0\figwidth

which is fine for now, but could break the code in some situations that don't involve a factor in my initial definition of the width variable. For example

\newcommand{\figwidth}{\textwidth}

would yield zero figure width:

width=0\textwidth,   % = 0\figwidth = 0

I have searched all the *.m files contained in the src folder of the matlab2tikz package for this factor but found no results in the code.

tl:dr; Does anyone know what is causing the magic factor 0.95092 and how to avoid it?
Thanks a lot in advance for your help!

Edit: PS, I previously posted this question on tex.stackexchange.com but received no reply. Should the issue be solved here, I will update my Stackexchange post with the solution.

@egeerardyn

This comment has been minimized.

Copy link
Member

commented May 26, 2015

The 0.95... comes from the way we currently handle subplots. This is already reported in #622, where I wrote a more extensive explanation of what happens and how you can temporarily patch your copy of matlab2tikz to mitigate this issue. We haven't fixed it yet, since we have to account for how different people use this feature: some specify no widths, some only height, some use absolute dimensions (5cm) and some use semantic ones (\figwidth). All are slightly different, but we try to keep those in the back of our heads. Unfortunately, we didn't do that for that semantic dimensions the last time we changed things.

However, in your case, I also noticed that you are defining \figwidth as a macro (using \newcommand or \def), not as a length. That is not a recommended approach, if you use \newlength and \setlength instead as on that wiki page, you don't need any work-arounds in your LaTeX code: 0.95\figwidth will mean what you expect.

Since this is a duplicate of #622, I will be closing this issue report. If you have have further questions regarding my response, please feel free to respond here. If you want to discuss that feature further, please do so in #622.

@egeerardyn egeerardyn closed this May 26, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.