Math & ScienceCommand like '\hfill' inside 'align' environment

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

Command like '\hfill' inside 'align' environment

Post by ezrahn »

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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Command like '\hfill' inside 'align' environment

Post by localghost »

The amsmath package provides several more environments for alignment.

Code: Select all

\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
ezrahn
Posts: 5
Joined: Tue Jun 21, 2011 12:37 am

Re: Command like '\hfill' inside 'align' environment

Post by ezrahn »

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

Re: Command like '\hfill' inside 'align' environment

Post by ezrahn »

Now if there is anyway I can underline them, it would have been great :D

\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..
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Command like '\hfill' inside 'align' environment

Post by localghost »

You can consider the align environment as some kind of array. So it is possible to use the \cline command for underlining.

Code: Select all

\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.
ezrahn
Posts: 5
Joined: Tue Jun 21, 2011 12:37 am

Re: Command like '\hfill' inside 'align' environment

Post by ezrahn »

Thanks, LocalGhost! Appreciate your help..
Post Reply