4

PS: exsheets isn't a must, all methods are welcome.

My document structure:

\documentclass{book}
\title{Introduction to Latex}
\author{Me}
\date{}
\begin{document}
    \chapter{first}
        \section{start}
            \subsection{install}
        \section{keyword}
    \chapter{second}
        \section{improve}
\end{document} 

I want that: If a section have at least one subsection, then the exercise section is like the following.

enter image description here

If a section doesn't have any subsection, then the exercise section is like the following. enter image description here

As I have shown, Exercises are counted in each chapter. I am new to latex so that I read the documentation of exsheets and still don't know how to do it.

2
  • I think that the images are in the wrong order. BTW, exsheets is a requirement for any other reason? or no matter the cat if he hunt this mouse ?
    – Fran
    Sep 16, 2017 at 6:52
  • @Fran exsheets isn't a must. All methods are welcome!
    – K.Robert
    Sep 16, 2017 at 6:58

3 Answers 3

2

An approach using custom environments with custom lists. The exercises in the subsection have a different indentation so you can compare how is adjusted.

I am not sure if you want the exercises in a colored box, in this case, uncomment the three lines with the word tcolorbox for a start.

mwe

\documentclass{article}
\newcounter{qcounter}
%\usepackage{tcolorbox}
\title{The art of make something}
\date{}\author{}
\def\df{Lore ipsum dolor sit amet. } % You guessed! Just print dummy text

\newenvironment{questions}{%
%\begin{tcolorbox}
\bigskip\noindent{\bfseries\large Exercises section \thesection:}
\begin{list}
{{\bfseries Exercise \thesection.\arabic{qcounter}:}}{
\setlength\labelwidth{-1em}
\setlength\labelsep{1em}
\setlength\leftmargin{0cm}
\usecounter{qcounter}}}{\end{list}
%\end{tcolorbox}
} 

\newenvironment{subquestions}{
\bigskip\noindent{\bfseries Exercises section \thesubsection:}
\begin{list}
{{\bfseries Exercise \thesubsection.\arabic{qcounter}:}}{
\setlength\labelwidth{8em}
\setlength\labelsep{1em}
\setlength\leftmargin{12em}
\usecounter{qcounter}}}{\end{list}} 

\begin{document}
\maketitle


\section{General programming}

\df\df\df\df\df\par

\begin{questions}
\item \df\df\df\df
\item \df\df\df\df\df\df\df  
\item \df\df
\item \df
\end{questions}

\subsection{Phyton language}

\df\df\df\df\df\par

\begin{subquestions}
\item \df\df\df\df
\item \df\df\df\df
\item \df\df
\item \df
\end{subquestions}

\end{document}
3
  • The counter seems not right. Exercises should be counted in a chapter . In addition, if I need to define environment, I hope that environment will automatically derive whether this section has a subsection, ie:, I only need to use \begin{questions} \end{questions}
    – K.Robert
    Sep 16, 2017 at 8:38
  • @K.Robert If you are using \chapter{}, and the first number of each exercise should be the counter of \chapter + the number of the item only, no matter is if the list is in a section or a subsection, then you only have to change Exercise \thesection.\arabic{qcounter} by Exercise \thechapter .\arabic{qcounter}. Right?
    – Fran
    Sep 16, 2017 at 11:23
  • still can't get the expected result@Fran
    – K.Robert
    Sep 16, 2017 at 11:36
2

Nothing special to consider with exsheets: change the counter setting and choose runin template. No need for custom environments in order to change the name form Question to Exercise.

\documentclass{book}

\usepackage{exsheets}
\SetupExSheets{
  counter-within={chapter} ,
  counter-format=\thechapter.qu[1] ,
  headings = runin ,
  question/name = Exercise
}

\begin{document}

\chapter{first}
\section{start}
\subsection{Exercises Section}

\begin{question}
  Review the documentation for your compiler and determine what file naming
  convention it uses. Compile and Run the main program from page~2.
\end{question}

\begin{question}
  Review the documentation for your compiler and determine what file naming
  convention it uses. Compile and Run the main program from page~2.
\end{question}

\section{Exercises Section}
\begin{question}
  Review the documentation for your compiler and determine what file naming
  convention it uses. Compile and Run the main program from page~2.
\end{question}

\begin{question}
  Review the documentation for your compiler and determine what file naming
  convention it uses. Compile and Run the main program from page~2.
\end{question}

\end{document}

enter image description here

Getting the colon after the exercise number requires a bit more work, though:

\usepackage{exsheets}

\DeclareInstance{exsheets-heading}{myrunin}{default}{
  runin = true ,
  number-post-code = \textbf{:}\space ,
  attach = { main[l,vc]points[l,vc](\linewidth+\marginparsep,0pt) } ,
  join = {
    main[r,vc]title[r,vc](0pt,0pt) ;
    main[r,vc]number[l,vc](.333em,0pt)
  }
}

\SetupExSheets{
  counter-within={chapter} ,
  counter-format=\thechapter.qu[1] ,
  headings = myrunin ,
  question/name = Exercise
}

The same (including the colon) using xsim, exsheets designated successor package. At first sight this looks more complicated but indeed it is more flexible as changes to the layout are much easier to achieve:

\documentclass{book}

\usepackage{xsim,needspace}

\DeclareExerciseEnvironmentTemplate{runin}
  {%
    \par\vspace{\baselineskip}
    \Needspace*{2\baselineskip}
    \noindent
    \textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}:}%
    \GetExercisePropertyT{subtitle}{ \textit{#1}} % <<< notice the space
    \IfInsideSolutionF{%
      \GetExercisePropertyT{points}{%
        \marginpar{%
          \printgoal{\PropertyValue}%
          \GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}%
          \,\IfExerciseGoalSingularTF{points}
              {\XSIMtranslate{point}}
              {\XSIMtranslate{points}}%
        }%
      }%
    }%
  }
  {}

\xsimsetup{
  exercise/the-counter = \thechapter.\arabic{exercise} ,
  exercise/template = runin
}

\begin{document}

\chapter{first}
\section{start}
\subsection{Exercises Section}

\begin{exercise}
  Review the documentation for your compiler and determine what file naming
  convention it uses. Compile and Run the main program from page~2.
\end{exercise}

\begin{exercise}
  Review the documentation for your compiler and determine what file naming
  convention it uses. Compile and Run the main program from page~2.
\end{exercise}

\section{Exercises Section}
\begin{exercise}
  Review the documentation for your compiler and determine what file naming
  convention it uses. Compile and Run the main program from page~2.
\end{exercise}

\begin{exercise}
  Review the documentation for your compiler and determine what file naming
  convention it uses. Compile and Run the main program from page~2.
\end{exercise}

\end{document}

enter image description here

0
\documentclass{book}
\title{Introduction to Latex}
\author{Me}
\date{}

\usepackage[dvipsnames]{xcolor}
\usepackage{exsheets}
\SetupExSheets{counter-within={chapter},counter-format=\thechapter.qu[1]}
\newenvironment{myquestion}
  {\question[name={Exercise}]}
  {\endquestion}


\newlength{\currentparindent}
\newenvironment{myset}
    {   \setlength{\currentparindent}{\parindent}
        \par
        \centering
        \begin{minipage}{\textwidth}
        \setlength{\parindent}{\currentparindent}
         \noindent\textbf{Exercise Section \thesubsection  }
        }
    {

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

enter image description here

This is my answer, but I still don't know how to avoid line feeds between the title and the content of the exercises.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .