枚举环境中的颜色框问题

枚举环境中的颜色框问题

我正在写考试答案。对于其中一道多项选择题,我决定使用颜色框将所有正确答案涂黑。顺便说一句,该问题的多个选项可能是正确的(LaTeX 并不关心)。

我遇到了两个问题:(1) colorbox 使我的文本超出页面范围;(2) 即使换行,行与行之间也会有一条细细的空白(应该是阴影)。此外,阴影线的宽度也不同。

如何让颜色框自动换行?如何让整个正确答案(即使在换行之后)都带有阴影?有没有更美观、更漂亮的方法为多项选择题的答案添加阴影?

下面是一个例子。

\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{color}

\definecolor{SolutionColor}{gray}{0.85}

\begin{document}

Choose all correct statements.
\begin{enumerate}
\item \colorbox{SolutionColor}{\bfseries Here is a true sentence.}
\item \colorbox{SolutionColor}{\bfseries If the rank of a $\boldsymbol{2 \times 2}$ matrix $\boldsymbol{A}$ is 1, then one can always find a vector $\boldsymbol{\mathbf{b} \in \mathbb{R}^2}$ so that $\boldsymbol{A \mathbf{x} = \mathbf{b}}$ does not have a solution.}
\end{enumerate}

Choose all correct statements.
\begin{enumerate}
\item \colorbox{SolutionColor}{\bfseries Here is a true sentence.}
\item \colorbox{SolutionColor}{\bfseries If the rank of a $\boldsymbol{2 \times 2}$ matrix $\boldsymbol{A}$ is 1, then one can always find a vector $\boldsymbol{\mathbf{b} \in \mathbb{R}^2}$} \par \colorbox{SolutionColor}{\bfseries so that $\boldsymbol{A \mathbf{x} = \mathbf{b}}$ does not have a solution.}
\end{enumerate}


\end{document}

在此处输入图片描述

答案1

框(此处为彩色框)不会跨行。您可以躲在里面,parbox以防这种情况:

\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{color,linegoal}

\definecolor{SolutionColor}{gray}{0.85}

\begin{document}

Choose all correct statements.
\begin{enumerate}
\item \colorbox{SolutionColor}{\parbox[t]{\linegoal}{\bfseries Here is a true sentence.}}
\item \colorbox{SolutionColor}{\parbox[t]{\linegoal}{\bfseries If the rank of a $\boldsymbol{2 \times 2}$ matrix $\boldsymbol{A}$ is 1, then one can always find a vector $\boldsymbol{\mathbf{b} \in \mathbb{R}^2}$ so that $\boldsymbol{A \mathbf{x} = \mathbf{b}}$ does not have a solution.}}
\end{enumerate}

Choose all correct statements.
\begin{enumerate}
\item \colorbox{SolutionColor}{\parbox[t]{\linegoal}{\bfseries Here is a true sentence.}}
\item \colorbox{SolutionColor}{\parbox[t]{\linegoal}{\bfseries If the rank of a $\boldsymbol{2 \times 2}$ matrix $\boldsymbol{A}$ is 1, then one can always find a vector $\boldsymbol{\mathbf{b} \in \mathbb{R}^2}$ \par so that $\boldsymbol{A \mathbf{x} = \mathbf{b}}$ does not have a solution.}}
\end{enumerate}


\end{document}

在此处输入图片描述

答案2

这是另一个选项,使用mdframed包;该命令\mysolu接收彩色框内容作为强制参数,并根据所需的规格对其进行排版:

\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{xcolor}
\usepackage{mdframed}

\definecolor{SolutionColor}{gray}{0.85}

\makeatletter
\renewrobustcmd*\mdf@makebox@out[2][\linewidth]{%
 \vskip-\baselineskip\noindent\hb@xt@\z@{%
    \noindent\makebox[\dimexpr #1\relax][l]{#2}}%
}%
\makeatother
\newmdenv[
  backgroundcolor=SolutionColor,
  hidealllines=true,
  innerleftmargin=3pt,
  innerrightmargin=3pt,
  skipabove=0pt,
  font=\bfseries
]{mysol}

\newcommand\mysolu[2][]{%
  \begin{mysol}[#1]#2\end{mysol}}

\begin{document}

\noindent Choose all correct statements.
\begin{enumerate}
\item\mysolu{Here is a true sentence.}
\item\mysolu{If the rank of a $\boldsymbol{2 \times 2}$ matrix $\boldsymbol{A}$ is 1, then one can always find a vector $\boldsymbol{\mathbf{b} \in \mathbb{R}^2}$ so that $\boldsymbol{A \mathbf{x} = \mathbf{b}}$ does not have a solution.}
\end{enumerate}

\end{document}

在此处输入图片描述

相关内容