I need to be able to underline equations involving fractions, which are aligned using the alignedat
environment from amsmath
. To be able to underline at all, I'm using the solution from this question - but when fractions get 'underlined', the line goes through the middle of the fraction rather than beneath it.
Also, is it possible to modify the underlining to make it a double underline?
Code - main file
\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}
Code - 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}
\underline{\underline{#1}}
in the definition of\ans
. The obvious problem is that the "tikzmark" is placed at the baseline. – egreg May 19 '13 at 19:14\ans
should wrap around the whole equation (code corrected to show this). I can see that's what the problem is, what I can't see is what the solution should be... – JustinT May 19 '13 at 19:38sol
(solution?) environment and\ans
(answer?) command. I ask as you appear to want to add underlining to\ans
which is harder as it is inside the alignment rather than tosol
where it is trivial to wrap the entire math in one or two underline. – David Carlisle Jun 24 '13 at 14:31