子问题的答案通常很短: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
。我定义了一个新命令\@subQuestionHeader@noItem
,它基本上只是 的输出,\show\@subQuestionHeader
没有\item
而是\hspace
。
\subQuestionOnSameLine
只需替换\@subQuestionHeader
为\@subQuestionHeader@noItem
,然后执行正常的\subQuestion
。
\@subQuestionHeader
在问题末尾重置,即组结束的位置。在此之前,所有\subQuestion
操作均将像 一样\subQuestionOnSameLine
。如果您想在 之后的新行上放置子问题,\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}