# Align all numbers, operators, variables, and insert blank spaces for variables not displayed

I would like to do the following

Align the word solution left and below question 1. then align all numbers, operators, variables, and insert blank spaces for variables not displayed. As shown in the first image below.

My Code

\documentclass{article}
\usepackage[fleqn]{amsmath} %[fleqn] used in co-ordinance with \begin{aligned}[t] to allow equations to align left neatly regardless of their width.
\usepackage{amssymb}
\usepackage{geometry}
\usepackage{cancel}
\usepackage{enumitem} %used for alphabetizing lists (and using roman numerals in lists). To use the aforementioned features when using this package, type in \begin{enumerate}[label=(\alph*)] (or \Alph* for uppercase or \roman*).
\setlength\arraycolsep{1pt} %used to ensure there are no large spaces between values in an array.
\author{Isaac King}
\title{1.1 Systems of Linear Equations}

\begin{document}
\maketitle
Solve each system in Exercises 1–4 by using elementary row operations on the equations or on the augmented matrix. Follow the systematic elimination procedure described in this section.
\begin{enumerate}
\item
$\begin{array}[t]{rcrc} x_1+5x_2&= &7 \\ -2x_1-7x_2&=-&5 \\ \end{array}$
\bigskip
\textbf{Solution:}
\\\\
$\begin{array}[t]{rcrc} x_1+5x_2&=7 \\ -2x_1-7x_2&=-5 \\\\ 2(x_1 +5x_2&=7) &\qquad\text{Replacement Eq. 2} \\ \underline{+-2x_1-7x_2}&\underline{=-5\vphantom{-2x_1}} \end{array}$
\end{enumerate}
\end{document}


• if you use code from answer from your previous question,than it would be nice from you, that you accept this answer (by clicking on check mark at top left side of answer). – Zarko Aug 18 '18 at 18:45
• Hello @Zarko thanks, I made sure to click the check mark! – I. King Aug 18 '18 at 19:51
• – Steven B. Segletes Aug 18 '18 at 23:14

Since you are new to Latex and your knowledge is limited, I recommend you to use the exam package and read the documentation. It is a lot more compatible with what you are doing and will for sure help you in assignment solutions as well as exam question/solutions preparation ;). Now, I have read your previous question as well as this one and came a solution to all of your requirements. Using the exam package will automatically solve some of your desires and will make the logic of your code a lot more simpler.

• You wanted to display 1-4 instead of 14. This can be simply achieved by doing 1 {}-{} 4 or 1 -- 4 (1 -- 4 will create a longer dash).
• Aligning numbers, operators, etc. is achieved via the alignedat environment from the amsmath package.
• Having multiple columns for the answers and/or questions is achieved by multicols environment from the multicol package.

Now for the final code, I have commented as much as I can and hopefully it all make sense. Oh just one thing, keep in mind that ~ will create a space (LaTeX is very picky with spaces). Hitting the space-bar three times will not output 3 spaces, but only one. Instead, typing ~~~ will register 3 spaces exactly. I have used tildes many times.

page 2

\documentclass[answers,12pt]{exam}
\usepackage{amsmath}            % Uses alignedat environment.

\usepackage{multicol}           % Allows muliple columns.

\usepackage{enumitem}           % Used for alphabetizing lists
% (and using roman numerals in lists).
% To use the aforementioned features
% when using this package in
% \begin{enumerate}[label=(\alph*)]
% (or \Alph* for uppercase or \roman*).

%\usepackage[fleqn]{amsmath}    % [fleqn] used in co-ordinance with
% \begin{aligned}[t] to allow equations
% to align left neatly regardless of
% their width.
\usepackage{amssymb}
\usepackage{geometry}
\usepackage{cancel}

\author{Isaac King}
\title{1.1 Systems of Linear Equations}

% Use \Add \Sub \Eq instead of + - =, respectively in mathmode.
% It is Case Sensitive! Those are used to insert space
% between the sign i.e. ~+~. Also, the {}+{} are used to pad
% empty atoms at either side of the operation.
% This is needed to guarantee the desired aligning.
\newcommand{\Sub}{\mathbf{{}~-~{}}}
\newcommand{\Eq}{\mathbf{{}~=~{}}}

% When it mathmode, use \Comment{comment to display}

\newcommand{\Line}[2]{\\[-2ex]\cline{#1-#2}\\[-4.25ex]}

% Uncomment the next line to add a frame around the solution.
\unframedsolutions

\begin{document}
\maketitle
Solve each system in Exercises 1 {}-{} 4 by 1 -- 4 using elementary row
operations on the equations or on the augmented matrix.
Follow the systematic elimination procedure described in this section.

% Enter a question environment and create a question via
% the \question command. Once the question is typed,
% use the \begin{solution}...\end{solution} for the solution.
\begin{questions}
% Question 1
\question This is the first question, solve
\begin{alignedat}[t]{3} x_{1} & \Add & 5x_{2} & \Eq & 7\\ -2x_{1} & \Sub & 7x_{2} & \Eq & -5 \end{alignedat}
% Question 1 Solution
\begin{solution}
\begin{alignedat}[t]{6} x_{1} & \Add & 5x_{2} & \Eq & 7\\ -2x_{1} & \Sub & 7x_{2} & \Eq & -5\\\\ 2(x_{1} & \Add & 5x_{2} & \Eq & 7) & \Comment{Replacement Eq. 2}\\ \Add -2x_{1} & \Sub & 7x_{2} & \Eq & -5~ \Line{1}{5} ~ & ~ & 3x_{2} & \Eq & 2~\\ \end{alignedat}\\[10pt]
\end{solution}

% Question 2
\question This is a question and the solution is divided into 2 columns!
% Question 2 Solution
\begin{solution}
\begin{multicols}{2}
\begin{alignedat}[t]{6} x_{1} & \Add & 5x_{2} & \Eq & 7\\ -2x_{1} & \Sub & 7x_{2} & \Eq & -5\\\\ 2(x_{1} & \Add & 5x_{2} & \Eq & 7) & \Comment{Eq. 2}\\ \Add -2x_{1} & \Sub & 7x_{2} & \Eq & -5~ \Line{1}{5} ~ & ~ & 3x_{2} & \Eq & 2~\\ \end{alignedat}\\[10pt]
% Now, a new column will start.
\begin{alignedat}[t]{6} x_{1} & \Add & 5x_{2} & \Eq & 7\\ -2x_{1} & \Sub & 7x_{2} & \Eq & -5\\\\ 2(x_{1} & \Add & 5x_{2} & \Eq & 7) & \Comment{Eq. 2}\\ \Add -2x_{1} & \Sub & 7x_{2} & \Eq & -5~ \Line{1}{5} ~ & ~ & 3x_{2} & \Eq & 2~\\ \end{alignedat}\\[10pt]
\end{multicols}
\end{solution}

% Question 3
\begin{multicols}{2}
% Left item
\question Question on the left side!! Solution on the right!!
% Question 3 Solution
\begin{solution}
\begin{enumerate}[label=(\alph*)]
\item % Top right item
\begin{alignedat}[t]{6} x_{1} & \Add & 5x_{2} & \Eq & 7\\ -2x_{1} & \Sub & 7x_{2} & \Eq & -5\\\\ 2(x_{1} & \Add & 5x_{2} & \Eq & 7) & \Comment{E2}\\ \Add -2x_{1} & \Sub & 7x_{2} & \Eq & -5~ \Line{1}{5} ~ & ~ & 3x_{2} & \Eq & 2~\\ \end{alignedat}\\[10pt]
\item % Bottom right item
\begin{alignedat}[t]{6} x_{1} & \Add & 5x_{2} & \Eq & 7\\ -2x_{1} & \Sub & 7x_{2} & \Eq & -5\\\\ 2(x_{1} & \Add & 5x_{2} & \Eq & 7) & \Comment{E2}\\ \Add -2x_{1} & \Sub & 7x_{2} & \Eq & -5~ \Line{1}{5} ~ & ~ & 3x_{2} & \Eq & 2~\\ \end{alignedat}\\[10pt]
\end{enumerate}
\end{solution}
\end{multicols}
% Question 4
\question This is a question and the (labelled!!)
solution is divided into 2 columns!
% Question 4 Solution
\begin{solution}
\begin{multicols}{2}
\begin{enumerate}[label=(\alph*)]
\item % Left item
\begin{alignedat}[t]{6} x_{1} & \Add & 5x_{2} & \Eq & 7\\ -2x_{1} & \Sub & 7x_{2} & \Eq & -5\\\\ 2(x_{1} & \Add & 5x_{2} & \Eq & 7) & \Comment{E2}\\ \Add -2x_{1} & \Sub & 7x_{2} & \Eq & -5~ \Line{1}{5} ~ & ~ & 3x_{2} & \Eq & 2~\\ \end{alignedat}\\[10pt]
\item % Right item
\begin{alignedat}[t]{6} x_{1} & \Add & 5x_{2} & \Eq & 7\\ -2x_{1} & \Sub & 7x_{2} & \Eq & -5\\\\ 2(x_{1} & \Add & 5x_{2} & \Eq & 7) & \Comment{E2}\\ \Add -2x_{1} & \Sub & 7x_{2} & \Eq & -5~ \Line{1}{5} ~ & ~ & 3x_{2} & \Eq & 2~\\ \end{alignedat}\\[10pt]
\end{enumerate}
\end{multicols}
\end{solution}
\end{questions}
\end{document}

• The different lengths of - have different uses and meanings. One - is for hyphenations in a compound word; two -- becomes an endash and is for ranges (like here), and three --- becomes an emdash and is for abrupt changes --- will someone answer that phone? --- in a sentence. – Teepeemm Aug 18 '18 at 23:40
• @M. Al Jumaily This is the greatest solution to all my problems!!!! Wow this is great. Thank you so much! I can finally finish the homework for this section in LaTeX. I know it's probably bad to ask multiple questions at once, but I just wanted to ask once. That was so I wouldn't have to keep asking multiple questions. Anyway, thanks again!!!!! – I. King Aug 19 '18 at 5:06