代码-主文件

代码-主文件

我需要能够对涉及分数的方程式进行下划线,这些方程式使用alignedat来自的环境进行对齐amsmath。为了能够进行下划线,我使用了来自的解决方案这个问题- 但是当分数被“下划线”时,线会穿过分数的中间而不是下方。

另外,是否可以修改下划线使其成为双下划线?

代码-主文件

\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[normalem]{ulem} % Underlining effects
\usepackage{environ} % Tinkering with environments
\usepackage{gensymb} % Degree symbol
\usepackage[pdfstartview=FitH,bookmarks=true]{hyperref} 
\usepackage[numbered]{bookmark} % PDF Bookmarks
\usepackage{tikz} % Underlining spanning alignment marks

\titleformat{\section}{\normalfont\large\bfseries}{Chapter }{0em}{\thesection: }
\renewcommand\sectionmark[1]{\markright{#1}} % Set up \rightmark
\renewcommand{\thesection}{\texorpdfstring{}{Chapter }\arabic{section}\texorpdfstring{}{:}} % Correct text for bookmarks

\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}
\renewcommand{\theexercise}{\texorpdfstring{}{Exercise }\arabic{section}\Alph{exercise}} % Correct text for bookmarks
\makeatletter
\providecommand*{\toclevel@exercise}{2} % Make sure exercises appear below sections in bookmarks
\makeatother

\renewcommand{\thepartno}{\roman{partno}} % Format part numbers as lower-case roman numerals
\renewcommand{\solutiontitle}{\noindent} % Format solution - just print solution as entered
%\newcommand{\ans}[1]{\uuline{#1}} % Double underline final answer
\newcommand{\ans}[1]{\tikzmarkin{\theexercise\thequestion\thepartno}#1\tikzmarkend{\theexercise\thequestion\thepartno}} % Double underline final answer

\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


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


\makeatletter % Use tikzmarks to underline across alignment marks
\tikzset{%
     remember picture with id/.style={%
       remember picture,
       overlay,
       save picture id=#1,
     },
     save picture id/.code={%
       \edef\pgf@temp{#1}%
       \immediate\write\pgfutil@auxout{%
         \noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
     },
     if picture id/.code args={#1#2#3}{%
       \@ifundefined{save@pt@#1}{%
         \pgfkeysalso{#3}%
       }{
         \pgfkeysalso{#2}%
       }
     }
   }

   \def\savepointas#1#2{%
  \expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}

\def\tmk@labeldef#1,#2\@nil{%
  \def\tmk@label{#1}%
  \def\tmk@def{#2}%
}

\tikzdeclarecoordinatesystem{pic}{%
  \pgfutil@in@,{#1}%
  \ifpgfutil@in@%
    \tmk@labeldef#1\@nil
  \else
    \tmk@labeldef#1,(0pt,0pt)\@nil
  \fi
  \@ifundefined{save@pt@\tmk@label}{%
    \tikz@scan@one@point\pgfutil@firstofone\tmk@def
  }{%
  \pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
  \pgfsys@getposition{\pgfpictureid}\save@this@pic%
  \pgf@process{\pgfpointorigin\save@this@pic}%
  \pgf@xa=\pgf@x
  \pgf@ya=\pgf@y
  \pgf@process{\pgfpointorigin\save@orig@pic}%
  \advance\pgf@x by -\pgf@xa
  \advance\pgf@y by -\pgf@ya
  }%
}
\makeatother

\newcommand{\tikzmarkin}[2][]{%
      \tikz[remember picture,overlay,baseline=0.25ex]
      \draw[line width=0.3pt,#1]
      (pic cs:#2) -- (0,0)
      ;}

\newcommand\tikzmarkend[2][]{%
\tikz[remember picture with id=#2,baseline=0.25ex] #1;}


\begin{document}

\unframedsolutions % Print solutions as plain text
\SolutionEmphasis{\color{blue}} % Print solutions in blue

\include{Chapter1}

\end{document}

代码 - Chapter1.tex

\section{Basic Algebra}
\begin{questions}
    \question Simplify the following fractions as much as possible.
    \begin{parts}
        \part $\dfrac{ab}{ac}$
        \begin{sol}
            \ans{\dfrac{ab}{ac} &= \dfrac{b}{c}}
        \end{sol}
    \end{parts}
\end{questions}

答案1

嗯。我发现A但这绝不是一个好的解决方案。

代码-主文件

\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[normalem]{ulem} % Underlining effects
\usepackage{environ} % Tinkering with environments
\usepackage{gensymb} % Degree symbol
\usepackage[pdfstartview=FitH,bookmarks=true]{hyperref} 
\usepackage[numbered]{bookmark} % PDF Bookmarks
\usepackage{tikz} % Underlining spanning alignment marks
\usepackage{etoolbox} % Control sequences

\titleformat{\section}{\normalfont\large\bfseries}{Chapter }{0em}{\thesection: }
\renewcommand\sectionmark[1]{\markright{#1}} % Set up \rightmark
\renewcommand{\thesection}{\texorpdfstring{}{Chapter }\arabic{section}\texorpdfstring{}{:}} % Correct text for bookmarks

\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}
\renewcommand{\theexercise}{\texorpdfstring{}{Exercise }\arabic{section}\Alph{exercise}} % Correct text for bookmarks
\makeatletter
\providecommand*{\toclevel@exercise}{2} % Make sure exercises appear below sections in bookmarks
\makeatother

\renewcommand{\thepartno}{\roman{partno}} % Format part numbers as lower-case roman numerals
\renewcommand{\solutiontitle}{\noindent} % Format solution - just print solution as entered
\newcommand{\ans}[2][0]{% Double underline answers to equations
    \tikzmarkin[#1ex]{\theexercise\thequestion\thepartno\thefigno a}
    \tikzmarkin[#1ex+0.35ex]{\theexercise\thequestion\thepartno\thefigno b}
    #2
    \tikzmarkend[#1ex+0.35ex]{\theexercise\thequestion\thepartno\thefigno b}
    \tikzmarkend[#1ex]{\theexercise\thequestion\thepartno\thefigno a}
}
\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


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


\makeatletter % Use tikzmarks to underline across alignment marks
\tikzset{%
     remember picture with id/.style={%
       remember picture,
       overlay,
       save picture id=#1,
     },
     save picture id/.code={%
       \edef\pgf@temp{#1}%
       \immediate\write\pgfutil@auxout{%
         \noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
     },
     if picture id/.code args={#1#2#3}{%
       \@ifundefined{save@pt@#1}{%
         \pgfkeysalso{#3}%
       }{
         \pgfkeysalso{#2}%
       }
     }
   }

   \def\savepointas#1#2{%
  \expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}

\def\tmk@labeldef#1,#2\@nil{%
  \def\tmk@label{#1}%
  \def\tmk@def{#2}%
}

\tikzdeclarecoordinatesystem{pic}{%
  \pgfutil@in@,{#1}%
  \ifpgfutil@in@%
    \tmk@labeldef#1\@nil
  \else
    \tmk@labeldef#1,(0pt,0pt)\@nil
  \fi
  \@ifundefined{save@pt@\tmk@label}{%
    \tikz@scan@one@point\pgfutil@firstofone\tmk@def
  }{%
  \pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
  \pgfsys@getposition{\pgfpictureid}\save@this@pic%
  \pgf@process{\pgfpointorigin\save@this@pic}%
  \pgf@xa=\pgf@x
  \pgf@ya=\pgf@y
  \pgf@process{\pgfpointorigin\save@orig@pic}%
  \advance\pgf@x by -\pgf@xa
  \advance\pgf@y by -\pgf@ya
  }%
}
\makeatother

\newcommand{\tikzmarkin}[2][0.25ex]{%
      \tikz[remember picture,overlay,baseline=#1]
      \draw[line width=0.4pt]
      (pic cs:#2) -- (0,0)
      ;}

\newcommand\tikzmarkend[2][0.25ex]{%
\tikz[remember picture with id=#2,baseline=#1];}


\begin{document}

\unframedsolutions % Print solutions as plain text
\SolutionEmphasis{\color{blue}} % Print solutions in blue

\include{Chapter1}

\end{document}

我确信有一个更好的解决方案,就像\uulineulem包中执行一些操作来确定下划线的正确垂直位置,但使用tikz以避免被对齐字符破坏。不幸的是,我的“专业知识”还没有那么深!


使用更新的解决方案进行编辑 - [可选] 第一个参数是降低下划线的垂直距离(以 exs 为单位)。

相关内容