列表形式的練習包

列表形式的練習包

我想使用該exercise包來製作使用該ExerciseList環境的練習清單。輸出應該如下例所示。

書上的例子

練習應如圖所示縮進,數字位於左側,就像在普通列表環境中一樣。這可以在包內完成嗎exercise

編輯:為了取悅@cfr,我特此發布我自己解決此問題的嘗試。代碼崩潰得很痛苦:

\documentclass[openright,book]{memoir}

%Dansk sprog:
\usepackage[utf8]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}
\renewcommand{\danishhyphenmins}{22}
%\OnehalfSpacing %hvis der oenskes halvanden linjeafstand

%Pakker
\usepackage[noDcommand]{kpfonts} % the kpfonts font
\usepackage{%
    amsmath,graphicx,enumerate,amstext,geometry,array,xfrac,bm,mathtools,siunitx,
    %tikz, pgfplots
    etoolbox, xparse, %til subexc
    fixltx2e, %fikser et par bugs i LaTeX-kernen
    microtype, %smaa fiks, der goer tekst lettere at laese
    varioref,
    }

\usepackage{exercise}
\renewcommand\ExerciseListName{} % I don't want any word like "exercise" anywhere
\renewcommand\ExerciseHeaderTitle{\Exercisetitle}

\renewcommand{\ExerciseListHeader}{\ExerciseHeaderDifficulty%
    \item[\ExerciseHeaderNB]\ExerciseHeaderTitle\ %
    \ExerciseHeaderOrigin\ignorespaces}

\renewenvironment{ExerciseList}{\enumerate[1]\beginExerciseListEnv}{\endExerciseListEnv\endenumerate}


\begin{document}

\begin{ExerciseList}
    \Exercise What is this?
    \Exercise What is that
    \Question What in the world?
    \subQuestion What is this?
    \ExeText We define $x = y$.
\end{ExerciseList}

\end{document}

答案1

由於在評論中,exsheets這種佈局的解決方案在這裡受到歡迎,因此......儘管用法與exercise包有很大不同...

該解決方案包含幾個步驟:

  • 借助和的幫助將 KOMA-Scriptaddmargin環境包裹在環境周圍。這會使問題正文按指定的邊距縮排(在下面的範例中)。該環境由套件提供,因此也可以與其他類別一起使用。questionetoolbox\AtBeginEnvironment\AtEndEnvironment3emaddmarginscrextend

  • margin-nr聲明一個受手冊中描述的實例啟發的新標題實例,exsheets該實例使用與環境設定相同的邊距addmargin3em在下面的範例中)將問題編號與文字邊距對齊。

  • 設定exsheets為使用新實例並新增一些用於節內編號的選項。

以下程式碼中的文件如下所示:

在此輸入影像描述

\documentclass{article}
\usepackage{scrextend}% not needed with a KOMA-Script class, provides the
                      % `addmargin' environment

\usepackage[load-headings]{exsheets}
\DeclareInstance{exsheets-heading}{mylist}{default}{
  runin = true ,
  attach = {
    main[l,vc]number[l,vc](-3em,0pt) ; % 3em = indent of question body
    main[r,vc]points[l,vc](\linewidth+\marginparsep,0pt)
  }
}

\SetupExSheets{
  headings = mylist , % use the new headings instance
  headings-format = \normalfont ,
  counter-format = se.qu ,
  counter-within = section
}


\usepackage{etoolbox}
% 3em = indent of question body :
\AtBeginEnvironment{question}{\addmargin[3em]{0em}}
\AtEndEnvironment{question}{\endaddmargin}

\usepackage{lipsum}

\begin{document}
\setcounter{section}{10}

\section*{Exercises}
\subsection*{Exercises to section \thesection}

\begin{question}
  \lipsum[4]
\end{question}

\begin{question}
  \lipsum[6]
\end{question}

\begin{question}
  \lipsum[10]
\end{question}

\end{document}

相關內容