패키지 와 함께 문제집을 조판하고 있습니다 exsheets
. 나는 설정된 문제의 구조를 반복하는 솔루션의 구조를 원합니다. 옵션을 사용 Chapter-hook
하면 section-hook
새 장/섹션의 솔루션이 인쇄될 때 솔루션 목록에 사용자 정의 코드를 추가할 수 있습니다. 내 MWE는 다음과 같습니다.
\documentclass{book}
\makeatletter
\@addtoreset{chapter}{part} % Reset \chapter numbering after each \part
\makeatother
\usepackage{exsheets}
\SetupExSheets{
chapter-hook = \chapter{Solutions to the chapter \thechapter},
section-hook = \section{Solutions to the section \thesection},
}
\begin{document}
\tableofcontents
\part{Problems}
\chapter{Mechanics}
\section{Kinematics}
\begin{question}
A kinematics problem.
\begin{solution}
Solution to the kinematics problem.
\end{solution}
\end{question}
\section{Dynamics}
\begin{question}
A dynamics problem.
\begin{solution}
Solution to the dynamics problem.
\end{solution}
\end{question}
\chapter{Electricity}
\section{Electrostatics}
\begin{question}
An electrostatics problem.
\begin{solution}
Solution to the electrostatics problem.
\end{solution}
\end{question}
\section{Electrodynamics}
\begin{question}
An electrodynamics problem.
\begin{solution}
Solution to the electrodynamics problem.
\end{solution}
\end{question}
\part{Solutions}
\printsolutions
\end{document}
내가 달성하고 싶은 것은 1 Solutions to Mechanics
current 1 Solutions to the chapter 1
대신 2 Solutions to Electricity
등 을 갖는 것입니다 2 Solutions to the chapter 2
. 도움을 주시면 감사하겠습니다.
답변1
패키지 참조를 통한 솔루션입니다 nameref
. 장/섹션 번호는 라벨 이름으로 사용됩니다.
\documentclass{book}
\makeatletter
\@addtoreset{chapter}{part} % Reset \chapter numbering after each \part
\makeatother
\usepackage{exsheets}
\usepackage{nameref}
\SetupExSheets{
chapter-hook = \chapter{Solutions to \nameref{CHAP:\thechapter}},
section-hook = \section{Solutions to \nameref{SEC:\thesection}},
}
\newcommand*{\chaplabel}{\label{CHAP:\thechapter}}
\newcommand*{\seclabel}{\label{SEC:\thesection}}
\begin{document}
\tableofcontents
\part{Problems}
\chapter{Mechanics}\chaplabel
\section{Kinematics}\seclabel
\begin{question}
A kinematics problem.
\begin{solution}
Solution to the kinematics problem.
\end{solution}
\end{question}
\section{Dynamics}\seclabel
\begin{question}
A dynamics problem.
\begin{solution}
Solution to the dynamics problem.
\end{solution}
\end{question}
\chapter{Electricity}\chaplabel
\section{Electrostatics}\seclabel
\begin{question}
An electrostatics problem.
\begin{solution}
Solution to the electrostatics problem.
\end{solution}
\end{question}
\section{Electrodynamics}\seclabel
\begin{question}
An electrodynamics problem.
\begin{solution}
Solution to the electrodynamics problem.
\end{solution}
\end{question}
\part{Solutions}
\printsolutions
\end{document}
레이블 설정은 \chapter
및 다음 에 포함될 수 있습니다 \section
.
- .
\mychapter
\chaplabel
- 이전 정의를 저장하고
\chapter
(예: package 를 통해letltxmacro
)\chapter
저장된 버전을 실행하고 추가하도록 재정의합니다\chaplabel
. - 필요한 인수 유형(별형, 선택적 인수)에 따라 (재)정의는 다소 쉽거나 더 복잡해집니다.
버전(여기서 \chaplabel
및 는 패키지에서 제공됨) 의 인수 \seclabel
에 사용됩니다 .<after code>
\titleformat
titlesec
\documentclass{book}
\makeatletter
\@addtoreset{chapter}{part} % Reset \chapter numbering after each \part
\makeatother
\usepackage{exsheets}
\usepackage{nameref}
\SetupExSheets{
chapter-hook = \chapter{Solutions to \nameref{CHAP:\thechapter}},
section-hook = \section{Solutions to \nameref{SEC:\thesection}},
}
\newcommand*{\chaplabel}{\label{CHAP:\thechapter}}
\newcommand*{\seclabel}{\label{SEC:\thesection}}
\usepackage{titlesec}
\titleformat{\chapter}{\normalfont\LARGE\bfseries}{\thechapter}{1em}%
{}[\chaplabel]
\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}%
{}[\seclabel]
\usepackage{etoolbox}
\pretocmd\printsolutions{%
\let\chaplabel\relax
\let\seclabel\relax
}{}{\errmessage{Patching \noexpand\printsolutions failed.}}
\begin{document}
\tableofcontents
\part{Problems}
\chapter{Mechanics}
\section{Kinematics}
\begin{question}
A kinematics problem.
\begin{solution}
Solution to the kinematics problem.
\end{solution}
\end{question}
\section{Dynamics}
\begin{question}
A dynamics problem.
\begin{solution}
Solution to the dynamics problem.
\end{solution}
\end{question}
\chapter{Electricity}
\section{Electrostatics}
\begin{question}
An electrostatics problem.
\begin{solution}
Solution to the electrostatics problem.
\end{solution}
\end{question}
\section{Electrodynamics}
\begin{question}
An electrodynamics problem.
\begin{solution}
Solution to the electrodynamics problem.
\end{solution}
\end{question}
\part{Solutions}
\printsolutions
\end{document}
무한 재귀를 피하는 방법은 다음과 같습니다.논평의 장과 섹션이 처리 되기 전에 비활성화하는 것입니다 \chaplabel
.\seclabel
\printsolutions
스위치로 약간의 변형이 가능합니다 \ifwithlabels
. 그런 다음 번호가 없는 장에 대해 레이블 설정을 비활성화할 수 있습니다. 예:
[...]
\newif\ifwithlabels
\newcommand*{\chaplabel}{\ifwithlabels\label{CHAP:\thechapter}\fi}
\newcommand*{\seclabel}{\ifwithlabels\label{SEC:\thesection}\fi}
\usepackage{titlesec}
\titleformat{\chapter}{\normalfont\LARGE\bfseries}{\thechapter}{1em}%
{}[\chaplabel]
\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}%
{}[\seclabel]
\usepackage{etoolbox}
\pretocmd\printsolutions{%
\withlabelsfalse
}{}{\errmessage{Patching \noexpand\printsolutions failed.}}
\begin{document}
\tableofcontents
\withlabelstrue
\part{Problems}
[...]