无需重复使用/textcolor即可对文本块进行着色

无需重复使用/textcolor即可对文本块进行着色

我想将答案涂成蓝色,但是我当前的解决方案并不真正可行,因为如果我在命令中使用\par\bigskip混乱,则每一行都需要单独涂成蓝色,即:\textcolor

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

返回错误,(我甚至不认为这是实现我想要的最有效的方法,但这是我能想到的唯一方法)

这是我的消息来源:

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

输出:

在此处输入图片描述

答案1

以下是处理每个条目的问题/答案部分的自动化方法:

在此处输入图片描述

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

环境的内容QandA收集每个单元格,并使用颜色设置它或不设置它。条件取决于您是否处于环境的第一行。第一行被视为问题(因此设置为黑色/默认),而后续行设置为颜色answercolor(设置为blue)。

答案2

为了回答您的问题,您可以\color{blue}将其放入一个组中,以便其影响不会持续到该组之外:

在此处输入图片描述

但是,我强烈建议您定义一个自定义环境,以简化所需输出的输入。每当您有大量手动插入的空格时,就该重新考虑一下了。

代码:

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

相关内容