## LaTeX forum ⇒ Math & Science ⇒ Command like '\hfill' inside 'align' environment

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
ezrahn
Posts: 5
Joined: Tue Jun 21, 2011 12:37 am

### Command like '\hfill' inside 'align' environment

Hi all,

I want to create simple multi-line equation for arithmetic worksheets, but it seemed to be quite tough to create.

I just want to create the following:

1234
+ 6
------
and I need to right-justify the numbers, while filling the space between the operator and the number. The \hfill command doesn't work in align* env, and using multiple '&' symbols to align the numbers doesn't seem to work.

eg.
\begin{align*}
& 1234&\\
+& 6&
\end{align*}

produces something like

1234
+6

I also tried using flalign env, since some comment in this forum suggests that I may be able to achieve what I want with extra tabs. I have not been able to successfully align the numbers with flalign, and it gives me line numbering, which I don't really want.

Can anyone suggest what I need to do to create this?

Thanks..
Last edited by ezrahn on Wed Jun 22, 2011 10:26 pm, edited 1 time in total.

Tags:

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
The amsmath package provides several more environments for alignment.
\documentclass{article}\usepackage{mathtools}   % loads »amsmath« \begin{document}   \begin{alignat*}{2}      && 1234 \\    + && 6    \end{alignat*}\end{document}

See the package manual for details. More about math typesetting in the excellent »Math mode« document.

Best regards and welcome to the board
Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

ezrahn
Posts: 5
Joined: Tue Jun 21, 2011 12:37 am
Works as expected. Thanks for your help.

ezrahn
Posts: 5
Joined: Tue Jun 21, 2011 12:37 am
Now if there is anyway I can underline them, it would have been great

\begin{alignat*}{2}
&& 1234\\
\underline{ +&& 6 }
\end{alignat*}

seems to be invalid, and

\begin{alignat*}{2}
&& 1234\\
\underline{+}&&\underline{ 6 }
\end{alignat*}

renders fine, but the two underlines do not make 1 continuous line..

I'd imagine that there must be a way to write this introductory arithmetic forms..

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
You can consider the align environment as some kind of array. So it is possible to use the \cline command for underlining.
\documentclass{article}\usepackage{mathtools}   % loads »amsmath« \begin{document}   \begin{alignat*}{2}      && 1234 \\    + &&    6 \\[-4\jot] \cline{1-3}   \end{alignat*}\end{document}

By the way, the forum software offers a »Code« environment to tag code as such. You can find it in the button list right above the input window while composing a post. Perhaps you noticed that I did so. Would be very kind if you use it, too. It just keeps a post clear and legible.
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

ezrahn
Posts: 5
Joined: Tue Jun 21, 2011 12:37 am