\documentclass{book}
\title{Introduction to Latex}
\author{Me}
\date{}
\usepackage[dvipsnames]{xcolor}
\usepackage{exsheets}
\SetupExSheets{counter-within={chapter}}
\newenvironment{myquestion}
{\question[name={myExercise}]}
{\endquestion}
\newlength{\currentparindent}
\newenvironment{myset}
{ \setlength{\currentparindent}{\parindent}
\par
\centering
\begin{minipage}{\textwidth}
\setlength{\parindent}{\currentparindent}
\noindent\colorbox{Gray!50}{Exercise \thesubsection }
{\color{Black} \hrule height 0.1ex} \vspace{0.5ex}}
{
\end{minipage}
}
\begin{document}
\chapter{first}
\section{start}
\subsection{install}
\begin{myset}
\begin{myquestion}
Review the documentation for your compiler and determine what file naming convention it uses. Compile and Run the main program from page 2.
\end{myquestion}
\end{myset}
\end{document}
第二个:如何将颜色框拉伸到行尾。我知道第二个问题有答案将颜色框拉伸至行尾
但是接受的答案会使颜色框下方的文本远离颜色框,这是我不想要的。
答案1
xsim
这是使用和 的概念上不同的版本tcolorbox
。
\documentclass{book}
\title{Introduction to Latex}
\author{Me}
\date{}
\usepackage{xsim}
\usepackage[skins]{tcolorbox}
\xsimsetup{solution/print=false}
\DeclareExerciseEnvironmentTemplate{tcolorbox}{%
\tcolorbox[enhanced,left=2pt,right=2pt,title=\GetExerciseName~\thesubsection,% append .\GetExerciseProperty{counter} to count inside subsection,
colback=white,colframe=black,colbacktitle=gray!50,coltitle=black,sharp corners=all]%
}{\endtcolorbox}
\DeclareExerciseType{myset}{
exercise-env=myset,
solution-env=mysetsol,
exercise-name=Exercise,
solution-name=Solution,
exercise-template=tcolorbox,
solution-template=tcolorbox,
within=chapter,
the-counter={\arabic{myset}},
}
\newcounter{myquestion}[myset]
\newenvironment{myquestion}
{\refstepcounter{myquestion}\textbf{Text here \themyquestion}\par}{}
\begin{document}
\chapter{first}
\section{start}
\subsection{install}
\begin{myset}
\begin{myquestion}
Review the documentation for your compiler and determine what file naming convention it uses. Compile and Run the main program from page 2.
\end{myquestion}
\end{myset}
\end{document}
答案2
像这样?这些依赖于framed
包的框架可能会跨页面中断
\documentclass{book}
\title{Introduction to Latex}
\author{Me}
\date{}
\usepackage{framed}
\usepackage[svgnames, dvipsnames]{xcolor}
\usepackage{exsheets}
\SetupExSheets{counter-within={chapter}}
\newenvironment{myquestion}
{\question[name={myExercise}]}
{\endquestion}
\newlength{\currentparindent}
\newenvironment{myset}
{\setlength{\currentparindent}{\parindent}
\setlength{\FrameRule}{0.8pt}
\par
%\centering
\framed
\setlength{\parindent}{\currentparindent}\vspace*{-\FrameSep}
\noindent\hspace*{-\dimexpr\FrameSep+\FrameRule}\rlap{\rule[-0.8ex]{\dimexpr\linewidth+2\FrameSep+2\FrameRule}{0.1ex}}
\hspace*{\dimexpr2\FrameRule-\fontdimen2\font}
\colorbox{Gainsboro!60!Lavender}{%
\makebox[\dimexpr\textwidth+\FrameSep+\fontdimen2\font][l]%
{\hspace{\dimexpr\FrameSep+2\FrameRule-\fontdimen2\font} Exercise \thesubsection}
}%
{\vspace{-2ex}}
}
{
\endframed
}
\begin{document}
\chapter{first}
\section{start}
\subsection{install}
\begin{myset}
\begin{myquestion}
Review the documentation for your compiler and determine what file naming convention it uses. Compile and Run the main program from page 2.
\end{myquestion}
\end{myset}
\end{document}