特定枚举样式

特定枚举样式

有没有办法用“枚举”重现这种样式列表?特别是想要用红色矩形中的白色数字逐项列出那些积分,而不必总是使用双 $$ 将它们置于数学模式(我希望每个“\item”都处于数学模式。)在此处输入图片描述

答案1

以下是两种解决方案:

一个带有 enumitem 的:

\documentclass[11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier, cabin}
\usepackage[showframe]{geometry}
\usepackage[svgnames]{xcolor} 
\usepackage{enumitem}

\newcommand*{\dd}{\mathop{\kern0pt\mathrm{d}}\mkern-2mu{}}

\begin{document}

\begin{enumerate}[label=\colorbox{Tomato}{\makebox[2em][r]{\arabic*}}, wide=0pt, labelsep=0.5em, leftmargin=*, font=\bfseries\large\sffamily\color{white}, before=\everymath{\displaystyle}]
  \item $\int\sqrt{1 + x^2}\dd x$. 
  \item $\int\sqrt{1 + 4x^2}\dd x$. 
  \item $\int\sqrt{1 + 4a^2x^2}\dd x$. 
  \item $\int\sqrt{3 + 2x^2}\dd x$. 
  \item $\int\frac{1}{\sqrt{1 + 2x^2}}\dd x$. 
  \item $\int\frac{1}{\sqrt{x^2-2x}}\dd x$. 
  \item $\int\frac{\dd x }{\sqrt{2x^2 + x + 1}}$. 
\end{enumerate}

\end{document} 

在此处输入图片描述

另一个是tabularx,在中输入数学模式displaystyle。我定义了一个mathtablist环境,它是一个 tabularx,它在每个新行增加一个计数器并将其显示在行的开头。此计数器可通过标签引用:

\documentclass[11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier, cabin}
\usepackage[showframe]{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{tabularx}

\newcounter{tabenum}
\newenvironment{mathtablist}%
{%
\setcounter{tabenum}{0}\everymath{\displaystyle}\renewcommand{\arraystretch}{2}
\setlength{\extrarowheight}{0.5ex}\noindent%
\tabularx{\linewidth}%
{@{}>{\refstepcounter{tabenum}\colorbox{Tomato}{\makebox[2em][r]{\bfseries\large\sffamily\color{white}\arabic{tabenum}} }\hspace{0.6em} \arraybackslash$ }X<{$}@{}}
}%
{%
\endtabularx
\setcounter{tabenum}{0}
}%

\newcommand*{\dd}{\mathop{\kern0pt\mathrm{d}}\mkern-2mu{}}

\begin{document}

Some text. Some text. Solve integral \ref{int-5}

\begin{mathtablist}
  \int√{1 + x²}\dd x. \\
  \int√{1 + 4x²}\dd x. \\
  \int√{1 + 4a²x²}\dd x. \\
  \int√{3 + 2x²}\dd x. \\
  \int\frac{1}{√{1 + 2x²}}\dd x.\label{int-5} \\
  \int\frac{1}{√{x²-2x}}\dd x. \\
  \int\frac{\dd x }{√{2x² + x + 1}}.
\end{mathtablist}

\end{document}

在此处输入图片描述

答案2

也许是这样的:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor,enumitem}

\newlength\myboxwd \setlength\myboxwd{2em}

\setlist[enumerate]{labelwidth=\myboxwd,
  label={%
    \colorbox{red}{%
      \makebox[\myboxwd][r]{%
      \textcolor{white}{\bfseries\sffamily\arabic*}%
    }%
  }%
}%
}

\newcommand{\iitem}[1]{\item \ensuremath{#1}}

\begin{document}

\begin{enumerate}
\item One
\item Two

\iitem {2 + 2 is a math expression} \ldots but this isn't
\end{enumerate}

\end{document}

相关内容