optidef
optidef copied to clipboard
Incorrect horizontal alignment with long constraint
I'd like to thank you for this very helpful package!
I have an issue with the horizontal alignment of a problem with a long constraint. Instead of the problem being moved/aligned to the left (in order to fit in the whole page), it overflows to the right. This only happens with the (referenced) mini environment, the horizontal alignment works perfectly with the mini* environment.
You will find a MWE below:
\documentclass{article}
\usepackage[short]{optidef}
\begin{document}
% The horizontal alignment works perfectly with mini* ...
\begin{mini*}
{}{x}
{}{}
\addConstraint{x}{\geq \sqrt{\hat{\sigma}^2+t_2}\sqrt{\frac{1-\epsilon}{\epsilon}} + \hat{\mu} + t_1 + \sqrt{\hat{\sigma}^2+r_2}\sqrt{3\Psi^{-1}_{\text{beta}}(1-2\epsilon)} + \hat{\mu} + r_1}
\end{mini*}
% ... but there's a problem with the referenced mini version of the same problem.
\begin{mini}
{}{x}
{\label{eq:1}}{}
\addConstraint{x}{\geq \sqrt{\hat{\sigma}^2+t_2}\sqrt{\frac{1-\epsilon}{\epsilon}} + \hat{\mu} + t_1 + \sqrt{\hat{\sigma}^2+r_2}\sqrt{3\Psi^{-1}_{\text{beta}}(1-2\epsilon)} + \hat{\mu} + r_1}
\end{mini}
\end{document}
Hi,
first of all thanks for noticing the bug. It is really hard to test the package against every case scenario, so I appreciate this type of feedback.
The issue appears to be related to how mini* and mini handle internally the alignments of the equations. For some reason I could not figure out yet, mini takes the width of the problem as the width of the objective and tries to center the problem. That is why you see the 'min x' in the center and the constraint overflow.
I need to fix the package. For the time being, you can use the following hack:
\begin{mini}
{}{\mathrlap{x} \phantom{x\geq \sqrt{\hat{\sigma}^2+t_2}\sqrt{\frac{1-\epsilon}{\epsilon}} + \hat{\mu} + t_1 + \sqrt{\hat{\sigma}^2+r_2}\sqrt{3\Psi^{-1}_{\text{beta}}(1-2\epsilon)} + \hat{\mu} + r_1}}
{\label{eq:1}}{}
\addConstraint{x}{\geq \sqrt{\hat{\sigma}^2+t_2}\sqrt{\frac{1-\epsilon}{\epsilon}} + \hat{\mu} + t_1 + \sqrt{\hat{\sigma}^2+r_2}\sqrt{3\Psi^{-1}_{\text{beta}}(1-2\epsilon)} + \hat{\mu} + r_1}
\end{mini}
So that you know what is going on, the hack forces the objective to appear as large as the constraint is but without displaying any additional text. So, if your problem objective is something like:
f(x)
And your largest constraint is something like:
g(x)+h(x)
Then you replace the objective with
\mathrlap{f(x)}\panthom{g(x)+h(x)}
I hope it solves the issue. Let me know otherwise.
Yeap, this "hack" indeed solves the issue. I also try to go through the code but couldn't figure out exactly why the alignment of mini* was fine but mini had a problem.
Should I close this issue or is better if it is left open in order to potentially fix this bug in the future?
Leave it open please, so it serves me as a reminder that I need to fix it.
I'm also going to +1 this problem... I'm having a ton of trouble getting it to align correctly. For whatever reason, it also appears to work whenever I place more than one constraint.
On the other hand, the hack does seem to work :) , but it's not particularly pretty to submit manuscripts for editing...
I have thought about this issue for a long time, but I cannot think of the right solution.
The difference between the mini
, mini*
, and mini!
environments is that, while the mini
is internally defined by the alignedat
environment as:
\begin{equation}
\begin{alignedat}
Optimization_problem
\end{alignedat}
\end{equation}
The other two use the the alignat
environment.
mini!
:
\begin{subequations}
\begin{alignat}
Optimization_problem
\end{alignat}
\end{subequations}
mini*
:
\begin{alignat*}
Optimization_problem
\end{alignat*}
For reasons that I cannot understand, the alignat
and alignedat
environments work differently in this specific case. The only fix I can think of is to re-define the mini
environment to use alignat
instead of alignedat
. However, if I do so, the equation number of the mini
environment is no longer automatically centered but instead it has to be defined by the user.
As such a change in the mini
environment would difficult the usage of the package for most users, I don't think is a good idea to implement it.
A possible solution would to be create an extra environment that can be used as an alternative to mini
where the user should select the location of the equation number. Besides that feature, this environment could also be used to solve this issue without complicating the syntax of the current environments.
Yeah, this would be interesting. I like the idea of the alternative environment; I can also ask around to see if anyone has an idea of why this would happen? This is surprising to me, I must say!
Thanks!