对齐所有数字、运算符、变量,并为未显示的变量插入空格

对齐所有数字、运算符、变量,并为未显示的变量插入空格

我想做以下事情

将单词 solution 对齐到问题 1 的左下方。然后对齐所有数字、运算符、变量,并为未显示的变量插入空格。如下面第一张图所示。

我的代码

\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}

空白空间和美观的对齐 编译代码

答案1

由于您是 Latex 的新手,并且知识有限,我建议您使用exam package并阅读文档。它与你正在做的事情更加兼容,并且肯定会帮助你完成作业以及准备考试问题/解决方案 ;)。现在,我已经阅读了你之前的问题以及这个问题,并找到了满足你所有要求的解决方案。使用该exam包将自动解决你的一些需求,并使你的代码逻辑更加简单。

  • 您想要显示 1-4 而不是 14。这可以通过执行1 {}-{} 41 -- 41 -- 4将创建更长的破折号)轻松实现。
  • 对齐数字、运算符等是通过包alignedat中的环境实现的amsmath
  • multicols通过包中的环境可以实现答案和/或问题的多列multicol

现在来看看最终的代码,我已经尽可能多地注释了,希望它们都说得通。哦,只有一件事,请记住,这~将创建一个空格(LaTeX 对空格非常挑剔)。按三次空格键不会输出 3 个空格,而只会输出一个。相反,输入~~~将准确记录 3 个空格。我多次使用了波浪线。

第 1 页

第2页

第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{\Add}{\mathbf{{}~+~{}}}
\newcommand{\Sub}{\mathbf{{}~-~{}}}
\newcommand{\Eq}{\mathbf{{}~=~{}}}

% When it mathmode, use \Comment{comment to display}
% for displaying your comments.
\newcommand{\Comment}[1]{\quad \text{#1}}

% Create the horizontal line when adding two addition
\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}

相关内容