1

My current code sets my equations weirdly to the left. I want to have the equations in the middle and the text to the right.

Problem code:

  \begin{flalign*} 
  &&I&= LA&& \text{ $I$ voidaan myös laskea kaavalla} \\
  &&I&=\frac{\phi}{\pi^2}&& \text{ yhdistämällä nämä saadaan} \\
  &&\phi &= LA\pi^2 &&\\
  && &= \SI[per-mode=fraction]{16697}{\candela\per\meter\squared}\cdot\SI{0.037}          {\meter\squared}\cdot \pi^2 &&\\
  && &\approx \SI{6097}{\candela}
  \end{flalign*}
2
  • define what is meant by weird? Looks ok to me when I compile it. Do you want more white space on left?
    – Leeser
    Jan 27, 2014 at 14:02
  • 4
    Please, make this into a minimal working example (MWE)
    – egreg
    Jan 27, 2014 at 14:02

1 Answer 1

1

The flalign environment has the first column flush with the left margin, and the final column flush with the right margin. Within each column the odd columns get aligned left, the even columns are aligned right. Thus you get several pairs of columns, appropriate for placing the left and right halves of an equation. Furthermore the column pairs are spread out over the line so that the space between the pairs is evenly distributed.

Thus if you have three column pairs and you wish your middle pair to be centered, just as it would be in an ordinary align environment, you need to ensure that your left and right pairs have equal width. One way to do this is to put space in the first column, and pack your text up in to \parboxes with the same width as the space introduced. An alternative is to make the first and last columns have zero width, with the text in the right most column sticking out to the left.

Output of solution 1

Sample output

Output of solution 2

Sample second output

Code for solution 1

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath,siunitx}

\begin{document}

Some text to indicate line length and page margins in relation to the
display below which is the object of interest.
\begin{flalign*}
  \hspace{10em}&& I&= LA
    &&\parbox[t]{10em}{\raggedleft $I$ voidaan myös laskea kaavalla} \\
  && I&=\frac{\phi}{\pi^2}
    &&\parbox[t]{10em}{\raggedleft yhdistämällä nämä saadaan} \\ 
  && \phi &= LA\pi^2\\
  && &= \SI[per-mode=fraction]{16697}{\candela\per\meter\squared}\cdot\SI{0.037}
          {\meter\squared}\cdot \pi^2\\ 
  && &\approx \SI{6097}{\candela}
\end{flalign*}
More text filling at least a whole line followed by the same material
without the text comments now in an ordinary \verb+align*+ environment.
\begin{align*}
  I&= LA\\
  I&=\frac{\phi}{\pi^2}\\
  \phi &= LA\pi^2\\
  &= \SI[per-mode=fraction]{16697}{\candela\per\meter\squared}\cdot\SI{0.037}          {\meter\squared}\cdot \pi^2\\
  &\approx \SI{6097}{\candela}
\end{align*}

Illustrational \verb+flalign+ with four column pairs
\begin{flalign*}
  a&b&c&d&e&f&gggg&hhhhhhhhhhhhhhhhhhhhhhh\\
  aaaaaaaa&b&c&d&e&f&gggg&h\\
\end{flalign*}

\end{document}

You need to take care that the total width is not more than the line length. You might prefer \raggedright in the side comments. Note the mathematics inside these \parboxes will be set in text style unless you write e.g. $\displaystyle ...$ each time (this makes a difference for symbols such as \sum and affects other aspects such as \frac).

Code for solution 2

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{mathtools,siunitx}

\begin{document}

Some text to indicate line length and page margins in relation to the
display below which is the object of interest.
\begin{flalign*}
  && I&= LA
    &&\mathllap{\text{$I$ voidaan myös laskea kaavalla}} \\
  && I&=\frac{\phi}{\pi^2}
    &&\mathllap{\text{yhdistämällä nämä saadaan}} \\ 
  && \phi &= LA\pi^2\\
  && &= \SI[per-mode=fraction]{16697}{\candela\per\meter\squared}\cdot\SI{0.037}
          {\meter\squared}\cdot \pi^2\\ 
  && &\approx \SI{6097}{\candela}
\end{flalign*}
More text filling at least a whole line followed by the same material
without the text comments now in an ordinary \verb+align*+ environment.
\begin{align*}
  I&= LA\\
  I&=\frac{\phi}{\pi^2}\\
  \phi &= LA\pi^2\\
  &= \SI[per-mode=fraction]{16697}{\candela\per\meter\squared}\cdot\SI{0.037}          {\meter\squared}\cdot \pi^2\\
  &\approx \SI{6097}{\candela}
\end{align*}

\end{document}

\mathllap is a command from the mathtools package that puts its contents in a box of width zero, with the contents protruding to the left. If you know that you essentially only want text in these comments you could instead use \llap{may side comment about $x$}, analogous to the \parbox commands in solution 1. With either of these commands, if your side comment is too long it will overlap the equation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.