5

I want to color the answers into blue however my current solution is not really viable as each line needs to be colored blue individually due to my use of \par\bigskip messes up \textcolor if its in the command ie:

\textcolor{blue}{$ =\frac{6}{3}$} \par\bigskip
     $ = 2$ }

returns errors, (I don't even think this is the most efficient way to achieve what i want either but its the only way I can think of)

Here is my source:

\documentclass{article}
\usepackage[margin=10pt, paperwidth=992pt, paperheight=1450pt]{geometry}
\usepackage[fleqn]{amsmath}
\usepackage{multicol}
\usepackage[shortlabels]{enumitem}
\usepackage[dvipsnames]{xcolor}
\usepackage{stix}
\begin{document}
\LARGE
\begin{enumerate}[\color{MidnightBlue} 1.]
\everymath{\displaystyle}
\item Simplify the following:
\begin{multicols}{3}
\begin{enumerate}[\color{MidnightBlue} (a),labelsep=5mm,itemsep=0.5\baselineskip,leftmargin=*]
    \item $ \frac{2}{3} + \frac{4}{3}$ \par\bigskip
    \textcolor{blue}{$ =\frac{6}{3}$} \par\bigskip
    \textcolor{blue}{ $ = 2$ }


    \item  $ \frac{1}{4} + \frac{1}{2}$ \par\bigskip
    \textcolor{blue}{$ =\frac{1}{4} + \frac{2}{4}$ }\par\bigskip
    \textcolor{blue}{$ =\frac{3}{4}$}

    \item $ \frac{4}{3} + \frac{2}{5}$ \par\bigskip
    \textcolor{blue}{ $ =\frac{20}{15} + \frac{6}{15}$ }\par\bigskip
    \textcolor{blue}{ $ =\frac{26}{15}$}

    \item $ \frac{2}{3} + \frac{1}{4}$ \par\bigskip
    $ =\frac{8}{12} + \frac{3}{12}$ \par\bigskip
    $ =\frac{11}{12}$

    \item $ \frac{4}{5} + \frac{3}{2}$ \par\bigskip
    $ =\frac{8}{10} + \frac{15}{10}$ \par\bigskip
    $ =\frac{23}{10}$

    \item $ \frac{5}{6} + \frac{2}{3}$ \par\bigskip
    $ =\frac{5}{6} + \frac{4}{6}$ \par\bigskip
    $ =\frac{9}{6}$
\end{enumerate}
\end{multicols}
\end{enumerate}
\end{document}

and the output:

enter image description here

  • Have you considered trying an math environment for equations instead, e.g. \textcolor{blue}{ \begin{align*} &= \frac{6}{3} \\ &= 2 \end{align*}} – user31729 May 26 '14 at 17:52
  • they are already in a math environment denoted by the $'s just shorthand to save space. – user1448093 May 26 '14 at 18:14
  • Yes, and it forces you those awkward \par\bigskip commands ;-) – user31729 May 26 '14 at 18:26
  • haha makes sense! i ended up using werners code which doesn't use $ :) – user1448093 May 27 '14 at 6:42
5

Here's an automated way of handling the question/answer part of every entry:

enter image description here

\documentclass{article}
\usepackage[margin=10pt, paperwidth=992pt, paperheight=1450pt]{geometry}
\usepackage[fleqn]{amsmath}
\usepackage{multicol,array,collcell,stix}
\usepackage[shortlabels]{enumitem}
\usepackage[dvipsnames]{xcolor}

\newcommand{\formatQandA}[1]{\ifnum\value{QandA}>1 \color{answercolor}\fi\displaystyle{}#1}
\newcolumntype{L}{>{\stepcounter{QandA}\collectcell\formatQandA}l<{\endcollectcell}}
\newcounter{QandA}
\newenvironment{QandA}
  {\setcounter{QandA}{0}% Start with row 0
   \renewcommand{\arraystretch}{2}% Stretch out array vertically
   $\array[t]{@{}L}}
  {\endarray$}
\colorlet{answercolor}{blue}

\begin{document}
\LARGE
\begin{enumerate}[\color{MidnightBlue} 1.]
  \item Simplify the following:
  \begin{multicols}{3}
    \begin{enumerate}[\color{MidnightBlue} (a),labelsep=5mm,itemsep=0.5\baselineskip,leftmargin=*]
      \item \begin{QandA}
        \frac{2}{3} + \frac{4}{3} \\
        = \frac{6}{3} \\
        = 2
      \end{QandA}

      \item \begin{QandA}
        \frac{1}{4} + \frac{1}{2} \\
        = \frac{1}{4} + \frac{2}{4} \\
        = \frac{3}{4}
      \end{QandA}

      \item \begin{QandA}
        \frac{4}{3} + \frac{2}{5} \\
        = \frac{20}{15} + \frac{6}{15} \\
        = \frac{26}{15}
      \end{QandA}

      \item \begin{QandA}
        \frac{2}{3} + \frac{1}{4} \\
        = \frac{8}{12} + \frac{3}{12} \\
        = \frac{11}{12}
      \end{QandA}

      \item \begin{QandA}
        \frac{4}{5} + \frac{3}{2} \\
        = \frac{8}{10} + \frac{15}{10} \\
        = \frac{23}{10}
      \end{QandA}

      \item \begin{QandA}
        \frac{5}{6} + \frac{2}{3} \\
        = \frac{5}{6} + \frac{4}{6} \\
        = \frac{9}{6}
      \end{QandA}
    \end{enumerate}
  \end{multicols}
\end{enumerate}
\end{document}

The contents of the QandA environment collects every cell and either sets it using a color or not. The condition is based on whether you're in the first row the environment or not. First row is considered the question (and is therefore set in black/default) while subsequent rows are set in color answercolor (let to blue).

4

To answer your question you can us \color{blue} and put it in a group so its effect does not continue past the group:

enter image description here

However, I would highly recommend you instead define a custom environment that simplifies the entry of the desired output. Whenever you have a lot of manually inserted spacing it is time to rethink things.

Code:

\documentclass{article}
\usepackage[margin=10pt, paperwidth=992pt, paperheight=1450pt]{geometry}
\usepackage[fleqn]{amsmath}
\usepackage{multicol}
\usepackage[shortlabels]{enumitem}
\usepackage[dvipsnames]{xcolor}
\usepackage{stix}
\begin{document}
\LARGE
\begin{enumerate}[\color{MidnightBlue} 1.]
\everymath{\displaystyle}
\item Simplify the following:
\begin{multicols}{3}
\begin{enumerate}[\color{MidnightBlue} (a),labelsep=5mm,itemsep=0.5\baselineskip,leftmargin=*]
    \item $ \frac{2}{3} + \frac{4}{3}$ \par\bigskip
    {\color{blue} $ =\frac{6}{3}$ \par\bigskip
    $ = 2$}


    \item  $ \frac{1}{4} + \frac{1}{2}$ \par\bigskip
    {\color{blue}$ =\frac{1}{4} + \frac{2}{4}$ \par\bigskip
    $ =\frac{3}{4}$}

    \item $ \frac{4}{3} + \frac{2}{5}$ \par\bigskip
    {\color{blue} $ =\frac{20}{15} + \frac{6}{15}$ \par\bigskip
    $ =\frac{26}{15}$}

    \item $ \frac{2}{3} + \frac{1}{4}$ \par\bigskip
    $ =\frac{8}{12} + \frac{3}{12}$ \par\bigskip
    $ =\frac{11}{12}$

    \item $ \frac{4}{5} + \frac{3}{2}$ \par\bigskip
    $ =\frac{8}{10} + \frac{15}{10}$ \par\bigskip
    $ =\frac{23}{10}$

    \item $ \frac{5}{6} + \frac{2}{3}$ \par\bigskip
    $ =\frac{5}{6} + \frac{4}{6}$ \par\bigskip
    $ =\frac{9}{6}$
\end{enumerate}
\end{multicols}
\end{enumerate}
\end{document}
  • could you quickly tell me how to define a custom environment, i'm pretty new at latex – user1448093 May 26 '14 at 18:00
  • @user1448093: Looks like Werner has already provided such an environment. Personally I would have done it slightly differently as I don't consider the intermediate steps as the answer. – Peter Grill May 26 '14 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.