我正在使用probsoln
,我想将解决方案作为 marginpar 和 footnotesize。请看下面MWE
的。Writelatex 不会编译,吐出
LaTeX Error: \begin{solutionnew} on input line 27 ended by \end{solution}.
TEX Studio 编译,但显示相同的错误。
除了将其设置为 marginpar 之外,我还想将其与问题的开头对齐,而不是与结尾对齐。也许用vspace
?
谢谢
MWE(如果你注释掉 \begin{document} 之前的三行,它就会正常工作):
\documentclass{article}
\usepackage{environ}
\usepackage{probsoln}
\showanswers
\begin{defproblem}{problem1}
We want to know the answer to The Ultimate Question of Life, the Universe, and Everything
\begin{onlysolution}
\begin{solution}
The answer is 42
\end{solution}
\end{onlysolution}
\end{defproblem}
%%This is how I'm trying to embrace in a marginpar the probsoln solution enviroment
\NewEnviron{solutionnew}{%
\marginpar{\footnotesize My solution name:\\ \BODY}}
\renewenvironment{solution}{\begin{solutionnew}}{\end{solutionnew}}
\begin{document}
\useproblem{problem1}
\end{document}
答案1
我把\renewenvironment
线改成了
\renewenvironment{solution}{\solutionnew}{\endsolutionnew}
您似乎还遗漏了环境定义的结束部分,solutionnew
我刚刚将其添加为{}
。也许宏形式更合适。
我还建议做得\marginpar
破烂一些。
请参阅此处的原始答案并进一步关注下文。
以下是 MWE:
\documentclass{article}
\usepackage{environ}
\usepackage{probsoln}
\showanswers
\begin{defproblem}{problem1}
We want to know the answer to The Ultimate Question of Life, the Universe, and Everything
\begin{onlysolution}
\begin{solution}
The answer is 42
\end{solution}
\end{onlysolution}
\end{defproblem}
%%This is how I'm trying to embrace in a marginpar the probsoln solution enviroment
\NewEnviron{solutionnew}{%
\marginpar{\raggedright\footnotesize My solution name:\\ \BODY}}{}
\renewenvironment{solution}{\solutionnew}{\endsolutionnew}
\begin{document}
\useproblem{problem1}
\end{document}
后续内容:回应 OP 的评论,可以通过在问题内容之前列出解决方案环境来获得问题顶部的解决方案。但请注意,\leavevmode
已添加 a,以处理\marginpar
作为段落中第一项发布的问题。
\documentclass{article}
\usepackage{lipsum}
\usepackage{environ}
\usepackage{probsoln}
\showanswers
\begin{defproblem}{problem1}
\begin{onlysolution}
\begin{solution}
The answer is 42
\end{solution}
\end{onlysolution}
We want to know the answer to The Ultimate Question of Life, the Universe, and Everything
\lipsum[1]
\end{defproblem}
%%This is how I'm trying to embrace in a marginpar the probsoln solution enviroment
\NewEnviron{solutionnew}{%
\leavevmode\marginpar{\raggedright\footnotesize My solution name:\\ \BODY}}{}
\renewenvironment{solution}{\solutionnew}{\endsolutionnew}
\begin{document}
\useproblem{problem1}
\end{document}