2

I have a very long equation in \align* environment so that I split it into two lines as shown in the screenshot blew

enter image description here

I want to write some text side to side the above part of the equation using &&\text{} ,but Latex throw it away in the margins and I do not know why this happens. Here is my code regarding this part :

\begin{align*}
X_{p}\psi &=  
X_p\bigl( \psi(p) \bigr) 
 + \sum_i \left(\left.\frac{\partial \psi}{\partial x^{i}}\right|_{p} \right) X_{p}\left(x^{i}-a^{i}\right)           &&\text{(plaplapla)} \\
&\phantom{{}= }+ \sum_i \sum_j X_{p}\left( \left(\zeta_{ij}\circ\phi \right)\left(x^{i}-a^{i}\right)\left(x^{j}-a^{j} \right) \right) .

The first & is using for aligning equations later, any my preamble just has the necessary packages for mathematics.

I appreciate any help. Thanks in advance.

2 Answers2

4

There are several possible solutions to this problem, depending both on the real equations and the real hints, and also on the page layout. It's easier if you load the geometry package, because the default horizontal margins with geometry are much more sensible. Second, you can use for the second line (without hint) the \mathrlap command from mathtools (which loads amsmath, so don't load the latter). alignat would let you control the horizontal spacing between equation and hints.

Here is an example:

\documentclass[a4paper,]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage[showframe]{geometry}%

\begin{document}

\begin{align*}
  X_{p}ψ&=
  X_p\bigl( ψ(p) \bigr)
  + ∑_i \left(\left.\frac{∂ ψ}{∂ xⁱ}\right|_{p} \right) X_{p}\left(xⁱ-aⁱ\right) &   & \text{some more or less long hint} \\
  &\phantom{{}= }+ ∑_i ∑_j \mathrlap{X_{p}\left( \left(\zeta_{ij} ∘ \phi \right)\left(xⁱ-aⁱ\right)\left(x^{j}-a^{j} \right) \right)+A+B.}
\end{align*}

\end{document} 

enter image description here

Bernard
  • 271,350
  • This solution is not preferable of course. It is horrible to show the frames. Is there an alternative solution ? – Hussein Eid Dec 17 '16 at 03:25
  • 2
    @HusseinEid - Have you looked at Bernard's code? Have you figured out what the showframe option does -- and that it's entirely possible to omit this option? – Mico Dec 17 '16 at 03:49
  • The only difference between this code and my code is the showframe option which creates a frame for every page. @Mico – Hussein Eid Dec 17 '16 at 03:51
  • @HusseinEid - Did you notice the & & \text{some more or less long hint} part? It's not in your posting... – Mico Dec 17 '16 at 03:52
  • No, it exists .. see my code again. @Mico – Hussein Eid Dec 17 '16 at 03:55
  • 1
    It exists… now, not when I answered. More seriously, the real important different is the use of \mathrlap for the hint, which allows the hint column to overlap the end of the first column (to some extent. I've updated the code, changing the equation to make that more apparent. As to the showframeoption, it is there only to visualize the hint does not go into the margin. – Bernard Dec 17 '16 at 13:52
2

Assuming the explanatory text string isn't all that long, it should be enough to separate it from the other material in the first row with a \quad or \qquad directive.

I would also like to recommend strongly that you get rid of the habit of using \left and \right with all math-mode parentheses. See, e.g., Is it ever bad to use \left and \right? for more information on this subject.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\hrule % Just to illustrate the width of the text block -- feel free to omit!
\begin{align*}
X_{p}\psi &= X_p\bigl( \psi(p) \bigr) 
  +\sum_i \biggl(\frac{\partial\psi}{\partial x^{i}}\biggr|_{p}\,\biggr) X_{p}(x^{i}-a^{i}) 
  \qquad\text{some explanatory thoughts}\\
&\quad+ \sum_i \sum_j X_{p}\bigl( (\zeta_{ij}\circ\phi)(x^{i}-a^{i})(x^{j}-a^{j}) \bigr) .
\end{align*}
\end{document}
Mico
  • 506,678