There is a way in order to reproduce this style listing with "enumerate"? In particular a want to itemize those integral with white numbers in a red rectangle and without using always the double $$ to put them in math mode (I want each '\item' to be alrady in math mode.) 
Asked
Active
Viewed 838 times
2
Andrea Leo
- 1,011
2 Answers
10
Here are two solutions:
One with 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}
The other with tabularx, entering mathmode in displaystyle. I define a mathtablist environment, which is a tabularx which increments a counter at each new row and displays it at the beginning of the row. This counter is referable with a label:
\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}
Bernard
- 271,350
-
-
I don't see with a list, unless you want to replace it with
{}. It could be done withtabularxandlistliketabs. What's the problem with typing a pair of$? With a good editor, you only have to type one. – Bernard Jul 29 '17 at 17:25 -
@Andrea Leo: I've updated my answer to add a solution which doesn't require typing
$$. – Bernard Jul 29 '17 at 18:26 -
@Bernard How can I replace the ractangles by a circles with numbers is put at centre at circles? – minhthien_2016 Jul 30 '17 at 04:24
-
@Bernard There is a problem. I can't use that ambient more then 1 time in the document because of: Error: Command \c@tabenum already defined. \begin{mathtablist} – Andrea Leo Jul 30 '17 at 09:17
-
-
@Andrea Leo: You're perfectly right. The reason for having for gotten is I first tested whether the code worked in the document body, without any environment, then turned it into an environment, and didn't check further. It's fixed now. Thanks for pointing the problem! B.t.w., note the second way doesn't break across pages. – Bernard Jul 30 '17 at 09:37
5
Perhaps like this:
\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}
jon
- 22,325
-
As Bernard more or less says: better to make a new brace-delimited command for the math. – jon Jul 29 '17 at 16:45
-
there is a way to reverse the thing? math mode without '{}' and normal text with '{}'? – Andrea Leo Jul 29 '17 at 16:48
-
@AndreaLeo -- Probably, but not in any way that makes sense. There's a reason it's called math mode: it's a special mode that needs to be started and stopped. Good TeX practice (in my opinion) means good, regular, and human-readable input. Often this means delimited arguments. Taking away the braces may slightly(!!) speed up your writing of the document, but it comes at the cost of obfuscating the input and making it less useful in the long run. In the case with the enumerate environment, you risk making very fragile macros. – jon Jul 30 '17 at 02:33
-
However, you can delimit the argument in non-orthodox ways. Consider:
\def\xxx#1/{\item \ensuremath{#1}}and then use\xxx 2 + 2 is a math expression / \ldots but this isn't. – jon Jul 30 '17 at 02:34


enumitem. For the automatic math modeit wouldn't be easy, to say the least. It would imply replacing the\itemcommand with another command displaying the numbers, then taking the integral as a second argument. This amounts to replacing a pair of$with a pair of braces. What's the difference? – Bernard Jul 29 '17 at 16:41