我想在文本区域中获取练习编号和标题,并在边距中打印示例编号。如何实现?我的 MWE 是:
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tasks}
\begin{document}
%\begin{exercise}
\begin{enumerate}
\item Simplify:
\begin{tasks}[style=itemize](4)
\task $5x+3x$
\task $5x-3x$
\task $-5x+3x$
\task $-5x-3x$
\end{tasks}
\item Simplify:
\begin{tasks}[style=itemize](4)
\task $-2a+3a+4a$
\task $-2a-3a+4a$
\task $-2a-3a-4a$
\task $-2a+3a-4a$
\end{tasks}
\end{enumerate}
%\end{exercise}
\end{document}
我所需的输出是:
答案1
我觉得这很接近你想要的。欢迎提出建议!
\documentclass{article}
\usepackage{lipsum}
\usepackage{amsmath,amssymb}
\usepackage[most]{tcolorbox}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage{tasks}
\usepackage{enumitem}
\usepackage{tikz}
\usetikzlibrary{calc}
\definecolor{mygreen}{HTML}{A5B37A}
\setlist{label=\textcolor{mygreen}{\bfseries\arabic*},leftmargin=0cm}
\settasks{%
counter-format=tsk[a],%
label-format=\bfseries\color{mygreen},%
label-offset=1ex,%
label-align=right,%
label-width=1ex,%
item-indent=0em,
column-sep=1em,
after-item-skip=0pt}
\newcounter{example}
\tcbset{
thmbox/.style={
enhanced,
breakable,
sharp corners=all,
fonttitle=\sffamily\bfseries,
top=0mm,
bottom=0mm,
right=0mm,
colback=white,
colframe=white,
colbacktitle=mygreen,
coltitle=white,
attach boxed title to top left,
boxed title style={sharp corners},
},
L/.style={
\stepcounter{example}
\draw [ultra thick,mygreen] ($(frame.north west)+(0.1em,0.1em)$)--($(frame.north east)+(0,0.1em)$);
\node [text=mygreen,anchor=south east] at (frame.north east) {\bfseries\sffamily FOUNDATION};
\node [draw,mygreen,text=black,thick,anchor=north east] at (frame.north west) {Example \the\value{example}};
},
}
\newtcbtheorem[]{proof}{Exercise}{thmbox,L}{theo}
\begin{document}
\begin{proof}{}{}
\begin{enumerate}
\item Simplify:
\begin{tasks}(4)
\task $5x+3x$
\task $5x-3x$
\task $-5x+3x$
\task $-5x-3x$
\end{tasks}
\item Simplify:
\begin{tasks}(4)
\task $-2a+3a+4a$
\task $-2a-3a+4a$
\task $-2a-3a-4a$
\task $-2a+3a-4a$
\end{tasks}
\end{enumerate}
\end{proof}
\end{document}
答案2
我不确定每个练习是否都有示例编号,所以我为它们添加了一个命令。你必须在第 5 行调整颜色:
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tasks,enumerate,xcolor,marginnote}
\colorlet{exercisecolor}{green!70!black!50!brown}
\settasks{counter-format=tsk[a],label-format=\sffamily\bfseries\color{exercisecolor}}
\newcounter{example}
\reversemarginpar
\newcommand\examplenumber{%
\refstepcounter{example}
\marginnote{%
\color{exercisecolor}%
\fbox{\sffamily Example \arabic{example}}%
}%
}%
\newenvironment{exercise}[2]{
{
\color{exercisecolor}%
\noindent\colorbox{exercisecolor}{%
\color{white}\sffamily\bfseries\large Exercise #1%
}\hfill\textsf{\bfseries #2}
\hrule depth 0.1em\relax
}%
\enumerate[\color{exercisecolor}\bfseries1]%
}{\endenumerate}
\begin{document}
\begin{exercise}{3A}{FOUNDATION}
\item\examplenumber Simplify:
\begin{tasks}(4)
\task $5x+3x$
\task $5x-3x$
\task $-5x+3x$
\task $-5x-3x$
\end{tasks}
\item Simplify:
\begin{tasks}(4)
\task $-2a+3a+4a$
\task $-2a-3a+4a$
\task $-2a-3a-4a$
\task $-2a+3a-4a$
\end{tasks}
\end{exercise}
\end{document}