# How to make a border for my own environment?

\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}


Two question: First: I want to make a border for my environment like this

Second: How to stretch the colorbox to the end of the line. I know there is an answer to the second question Stretching colorbox to the end of line

But the accepted answer will make the text below the colorbox away from the colorbox, which I don't want.

• Why don't you use tcolorbox? That would be easier. Sep 16 '17 at 16:06
• @TeXnician: I thought that too, but there's an error message when trying to wrap a tcolorbox around it: \__driver_color_pickup_aux:w has an extra }. I encountered the same error message when trying to use tasks within tcolorbox recently...
– user31729
Sep 16 '17 at 16:07
• @ChristianHupfer I know that tcb is okay with xsim, but never tried with exsheets. Probably an issue of wrapping in so many environments. Sep 16 '17 at 16:09
• @TeXnician: I have not used xsim yet
– user31729
Sep 16 '17 at 16:12

Here's a conceptually different version using xsim and 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}


Like this? These frames, which rely on the framed package, can break across pages

\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}
`

• No, the text below get far away. And I want a border. Sep 16 '17 at 16:29
• Do you mean a frame? Sep 16 '17 at 16:30
• Yes, and I don't want the text below get far away. Sep 16 '17 at 16:31
• @K.Robert: I've updated my answer. Sep 16 '17 at 18:32