LaTeX forum ⇒ Math & ScienceCommand 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

Postby ezrahn » Tue Jun 21, 2011 1:51 am

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:

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Tue Jun 21, 2011 8:32 pm

The amsmath package provides several more environments for alignment.
  1. \documentclass{article}
  2. \usepackage{mathtools} % loads »amsmath«
  3.  
  4. \begin{document}
  5. \begin{alignat*}{2}
  6. && 1234 \\
  7. + && 6
  8. \end{alignat*}
  9. \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
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ 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

Postby ezrahn » Wed Jun 22, 2011 12:06 am

Works as expected. Thanks for your help.

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

Postby ezrahn » Wed Jun 22, 2011 2:33 am

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: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Wed Jun 22, 2011 9:34 am

You can consider the align environment as some kind of array. So it is possible to use the \cline command for underlining.
  1. \documentclass{article}
  2. \usepackage{mathtools} % loads »amsmath«
  3.  
  4. \begin{document}
  5. \begin{alignat*}{2}
  6. && 1234 \\
  7. + && 6 \\[-4\jot] \cline{1-3}
  8. \end{alignat*}
  9. \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
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ 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

Postby ezrahn » Wed Jun 22, 2011 8:13 pm

Thanks, LocalGhost! Appreciate your help..


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 6 guests