如何(使用包 exsheets)在每个部分或小节末尾制作一个练习部分,如下所示?

如何(使用包 exsheets)在每个部分或小节末尾制作一个练习部分,如下所示?

PS:exsheets不是必须的,所有方法都欢迎。

我的文档结构:

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

我想要的是:如果一个部分至少有一个小节,那么练习部分如下所示。

在此处输入图片描述

如果某个部分没有任何小节,那么练习部分如下所示。 在此处输入图片描述

正如我所展示的,练习被计入每章。我是 Latex 的新手,所以我阅读了 exsheets 的文档,但仍然不知道该怎么做。

答案1

一种使用自定义环境和自定义列表的方法。本节中的练习具有不同的缩进,因此您可以比较如何调整。

我不确定您是否希望在彩色框中进行练习,在这种情况下,请先取消注释带有单词的三行tcolorbox

姆韦

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

答案2

无需特别考虑exsheets:更改计数器设置并选择runin模板。无需自定义环境即可更改名称表单问题锻炼

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

在此处输入图片描述

不过,要获得运动数字后的冒号还需要做更多的工作:

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

相同(包括冒号)使用xsimexsheets指定后继包。乍一看这看起来更复杂,但实际上它更灵活,因为布局的更改更容易实现:

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

在此处输入图片描述

答案3

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

在此处输入图片描述

这是我的答案,但是我仍然不知道如何避免练习标题和内容之间的换行。

相关内容