子問題的答案通常很短:a) 2、b) -15、c) 21 如何強制對任何給定的子問題進行無換行? MWE 關注
%
%--------------------------------------------------------------------------------------------------------- %
\documentclass{book}
%--------------------------------------------------------------------------------------------------------- %
%
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb} %
\usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,driver=none,lmargin=25mm,vmargin=20mm,showframe,showcrop]{geometry} % verbose,showcrop,showframe=inner frame
\usepackage[a4,frame,center]{crop} % pageframe
\usepackage[lastexercise,answerdelayed]{exercise}
%
\setlength{\marginparsep}{0mm} %
%
\renewcommand{\subQuestionNB}{\alph{subQuestion}) }
\renewcommand{\AnswerHeader}{\medskip{\textbf{\AnswerName\ %
\ExerciseHeaderNB}\smallskip}}
\renewcommand{\ExerciseHeader}{\textbf{\quad\:\ExerciseName\;\ExerciseHeaderNB\ExerciseHeaderTitle\ExerciseHeaderOrigin} %
\par\nopagebreak\medskip}
\setlength{\subQuestionIndent}{16.8pt}
\renewcounter{Exercise}[chapter] % Reset counter every chapter
\renewcounter{Answer}[chapter] %
\newcounter{Problem}[chapter] %
%
\def\AnswerName{\par{Answers to questions on chapter}} %
%
\begin{document}
\begin{Exercise}[label={E1},name={Exercises on chapter},counter={Problem}]
\Question{What is the symbol for iron?}
\Question{What is the symbol for hydrogen?}
\end{Exercise}
\begin{Exercise}[label={E2},name={Exercises on chapter},counter={Problem}]
\Question{What is the symbol for iron?}
\Question{For hydrogen, state the following:}
\subQuestion{the valency?} \subQuestion{the atomic number?} \subQuestion{the density?}
\end{Exercise}
\begin{Answer}[ref={E1}]
\Question{Fe}
\Question{H}
\end{Answer}
\begin{Answer}[ref={E2}]
\Question{Fe}
\Question{}
\subQuestion{2}
\subQuestion{1 - Want this answer to follow on same line as (a)}
\subQuestion{small - and this answer, too}
\end{Answer}
\shipoutAnswer
\end{document}
答案1
我不熟悉練習包,但我在文件中沒有找到任何支持在同一行找到答案的內容。因此我\subQuestionOnSameLine
為此定義了一個新命令。
負責將子問題放在新行上的命令是\item
in \@subQuestionHeader
。我定義了一個新命令,基本上它只是不帶but a\@subQuestionHeader@noItem
的輸出。\show\@subQuestionHeader
\item
\hspace
\subQuestionOnSameLine
只需替換\@subQuestionHeader
為\@subQuestionHeader@noItem
,然後執行正常的\subQuestion
.
\@subQuestionHeader
在小組結束的問題結束時重置。在那之前一切\subQuestion
都會表現得像\subQuestionOnSameLine
。如果您想在 a 之後放置一個子問題,\subQuestionOnSameLine
您可以使用\subQuestionOnNewLine
.
請注意,每個問題的第一個子問題應始終是普通問題\subQuestion
,而不是\subQuestionOnSameLine
.
\documentclass{book}
% ------ packages ------
\usepackage[fleqn]{amsmath}
\usepackage{amsthm,amssymb}
\usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,driver=none,lmargin=25mm,vmargin=20mm,showframe,showcrop]{geometry}
\usepackage[a4,frame,center]{crop}
\usepackage[lastexercise,answerdelayed]{exercise}
% ------ \subQuestionOnSameLine ------
\makeatletter
\let \@subQuestionHeader@original=\@subQuestionHeader
\newcommand{\@subQuestionHeader@noItem}{%
\hspace{1cm}%
\begingroup
\@getsubQuestionInfo
\subQuestionHeaderDifficulty
\subQuestionNB
\endgroup
\begingroup
\@getsubQuestionInfo
\subQuestionHeaderTitle
\endgroup%
\ignorespaces
}%
\newcommand{\subQuestionOnSameLine}{%
\let \@subQuestionHeader=\@subQuestionHeader@noItem
\subQuestion
}
\newcommand{\subQuestionOnNewLine}{%
\let \@subQuestionHeader=\@subQuestionHeader@original
\subQuestion
}
\makeatother
% ------ layout ------
\setlength{\marginparsep}{0mm}
\renewcommand{\subQuestionNB}{\alph{subQuestion}) }
\renewcommand{\AnswerHeader}{\medskip{\textbf{\AnswerName\
\ExerciseHeaderNB}\smallskip}}
\renewcommand{\ExerciseHeader}{\textbf{\quad\:\ExerciseName\;\ExerciseHeaderNB\ExerciseHeaderTitle\ExerciseHeaderOrigin}
\par\nopagebreak\medskip}
\setlength{\subQuestionIndent}{16.8pt}
\renewcounter{Exercise}[chapter] % Reset counter every chapter
\renewcounter{Answer}[chapter]
\newcounter{Problem}[chapter]
\def\AnswerName{\par{Answers to questions on chapter}}
% ------ document ------
\begin{document}
\begin{Exercise}[label={E1},name={Exercises on chapter},counter={Problem}]
\Question{What is the symbol for iron?}
\Question{What is the symbol for hydrogen?}
\end{Exercise}
\begin{Exercise}[label={E2},name={Exercises on chapter},counter={Problem}]
\Question{What is the symbol for iron?}
\Question{For hydrogen, state the following:}
\subQuestion{the valency} \subQuestion{the atomic number} \subQuestion{the density}
\end{Exercise}
\begin{Answer}[ref={E1}]
\Question{Fe}
\Question{H}
\end{Answer}
\begin{Answer}[ref={E2}]
\Question{Fe}
\Question{}
\subQuestion{answer to~a}
\subQuestionOnSameLine{answer to~b}
\subQuestionOnSameLine{answer to~c}
\end{Answer}
\shipoutAnswer
\end{document}