代码-主文件

代码-主文件

我正在尝试使用类编写一些练习的解决方案exam。为了正确对齐方程式,我还使用了aligned来自的环境amsmath

为了避免过多的重复输入,我尝试使用在 -内自动etoolbox启动/结束环境,但在编译时,抱怨缺少。alignedsolution\LaTeX$

下面的代码可以工作,注释掉的行显示了我想要做的事情。有什么建议吗?如何让它工作,或者有更好的方法来实现相同的结果?

\documentclass[answers]{exam}

\usepackage{xcolor} % Use colour!
\usepackage{titlesec} % Allow creation of new sectioning commands
\usepackage{amsmath} % Needed for splitting equations over multiple lines
\usepackage{ulem} % Underlining effects
\usepackage{etoolbox} % Tinkering with environments

\titleclass{\exercise}{straight}[\section]  % Create new 'section' command for exercises - this replaces \subsection
\newcounter{exercise}
\titleformat{\exercise}
  {\normalfont\large\bfseries}{}{1em}{Exercise \theexercise}
\titlespacing*{\exercise}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcommand{\exerciseautorefname}{exercise}


\begin{document}

\unframedsolutions % Print solutions as plain text
\SolutionEmphasis{\color{blue}} % Print solutions in blue
\renewcommand{\thepartno}{\roman{partno}} % Format part numbers as lower-case roman numerals
\renewcommand\theexercise{\thesection\Alph{exercise}} % Print exercise numbers as 1A, etc...
\renewcommand{\solutiontitle}{\noindent} % Format solution - just print solution as entered
\newcommand{\ans}[1]{\uuline{#1}} % Double underline final answer

%\AtBeginEnvironment{solution}{$\begin{aligned}}
%\AtEndEnvironment{solution}{\end{aligned}$}

\section{Basic Algebra}
\exercise{}
\begin{questions}
    \question Simplify the following expressions by collecting like terms:

    \begin{parts}
        \part $8x + 3x + 4x - 6x$
        \begin{solution}
            $\begin{aligned}
                3p + 3 + 5p - 7 - 7p - 9 &= 3p + 5p - 7p + 3 - 7 - 9\\
                &= \ans{p - 13}\end{aligned}$
        \end{solution}

    \end{parts}

\end{questions}

\end{document}

对此做了更多工作后,我发现自己需要在某些地方使用多个对齐点。alignedat 环境看起来正是我需要的;我只是无法让它在此上下文中工作。

代码-主文件

\documentclass[answers]{exam}

\addtolength{\textwidth}{1cm}
\addtolength{\hoffset}{-0.5cm}
\addtolength{\textheight}{1cm}
\addtolength{\voffset}{-0.5cm}

\usepackage{xcolor} % Use colour!
\usepackage{titlesec} % Allow creation of new sectioning commands
\usepackage{amsmath} % Needed for splitting equations over multiple lines
\usepackage{ulem} % Underlining effects
\usepackage{environ} % Tinkering with environments
\usepackage{gensymb} % Degree symbol
\usepackage[pdfstartview=FitH,bookmarks=true]{hyperref} 
\usepackage{bookmark} % PDF Bookmarks
\bookmarksetup{numbered} % Include numbers in PDF bookmarks

\titleformat{\section}{\normalfont\large\bfseries}{Chapter }{0em}{\thesection: }

\titleclass{\exercise}{straight}[\section]  % Create new 'section' command for exercises - this replaces \subsection
\newcounter{exercise}
\titleformat{\exercise}{\normalfont\large\bfseries}{Exercise }{0em}{\theexercise}
\titlespacing*{\exercise}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcommand{\exerciseautorefname}{exercise}
\makeatletter
\providecommand*{\toclevel@exercise}{2} % Make sure exercises appear below sections in bookmarks
\makeatother

\pagestyle{headandfoot} % Let's have both
\header{\oddeven{Exercise \theexercise}{Chapter \thesection: \rightmark}}{Core 1}{\oddeven{Chapter \thesection: \rightmark}{Exercise \theexercise}}
\headrule
\footer{\oddeven{}{\thepage}}{}{\oddeven{\thepage}{}}
\footrule

\renewcommand\sectionmark[1]{\markright{#1}} % Set up \rightmark

\begin{document}

\unframedsolutions % Print solutions as plain text
\SolutionEmphasis{\color{blue}} % Print solutions in blue
\renewcommand{\thepartno}{\roman{partno}} % Format part numbers as lower-case roman numerals
\renewcommand\theexercise{\thesection\Alph{exercise}} % Print exercise numbers as 1A, etc...
\renewcommand{\solutiontitle}{\noindent} % Format solution - just print solution as entered
\newcommand{\ans}[1]{\uuline{#1}} % Double underline final answer

\NewEnviron{sol}{ % Align solutions sensibly
    \begin{solution}
        $\begin{alignedat}{2}
            \BODY
        \end{alignedat}$
    \end{solution}
}

\include{Chapter1}

\end{document}

代码 - Chapter1.tex

\section{Basic Algebra}

\exercise{}
\begin{questions}
    \question Solve the following equations.
    \begin{parts}
        \part $5a - 32 = 68$
        \begin{sol}
            5a - 32 = 68 &\implies 5a &= 100\\
            &\implies \ans{a &= 20}
        \end{sol}
    \end{parts}
\end{questions}

答案1

问题出在第1章.tex

我还没有完全理解&(有效地)交替使用“奇数”出现作为对齐点(左侧的列与右侧对齐,右侧的列与左侧对齐),并且“偶数”出现用于分隔列组。

因此,如果您使用5a - 32 = 68 &\implies 5a &= 100(如上所示),这将排版5a - 32 = 68为右对齐,\implies设置在列之间,然后5a左对齐,=在列之间对齐,然后68右对齐。正确的用法是

\section{Basic Algebra}

\exercise{}
\begin{questions}
    \question Solve the following equations.
    \begin{parts}
        \part $5a - 32 = 68$
        \begin{sol}
            5a - 32 = 68 &\implies & 5a &= 100\\
            &\implies & \ans{a &= 20}
        \end{sol}
    \end{parts}
\end{questions}

&请注意,后面的额外内容&\implies是开始一个新的对齐组。

相关内容