带答案包的两列

带答案包的两列

我想在我的教科书中使用multicol包中包。我该如何解决这个问题?answers

\documentclass[12pt,a4paper]{book}
\usepackage{enumitem,calc}
\setlist[enumerate]{labelsep=10pt,leftmargin=45pt}
\setlist[enumerate,1]{label= $\arabic*.$}
\setlist[enumerate,2]{leftmargin=*,label=\theenumi$\arabic*$),ref=\theenumi$\arabic*$)}
\usepackage{amsmath,amsthm,amssymb}
\newtheorem{exer}{Exercise}[section]
\usepackage{answers}
\Newassociation{solution}{Solution}{ans}
\renewcommand{\Solutionlabel}[1]{#1}
\usepackage{multicol}
\begin{document}
\Opensolutionfile{ans}[exer1.1]
\begin{exer}\label{exer1.1}\mbox{ }
\begin{enumerate}
    \item First problem
    \begin{solution}
    Sol. of first problem
    \end{solution} 
    \item Second problem
\begin{enumerate}
\begin{multicols}{2}
    \item Sub second problem
    \begin{solution}
        Sol. of 2.1
    \end{solution} 
    \item Sub second problem
    \begin{solution}
        Sol. of 2.2
    \end{solution}  
    \item Sub second problem
    \begin{solution}
        Sol. of 2.3
    \end{solution} 
    \item Sub second problem
    \begin{solution}
        Sol. of 2.4
    \end{solution}  
\end{multicols}     
\end{enumerate} 
\end{enumerate}
\end{exer}
\Closesolutionfile{ans}

\bigskip

\section*{\centering Solutions of Chapter \thechapter}

\subsection*{Solutions of Exercise \ref{exer1.1}}
\input{exer1.1}
\end{document}

答案1

如果我理解正确的话你应该将multicols环境添加到你的答案文件中,这里的mtmulticols环境被定义为执行此操作

编辑:已更新这个想法是输入

\Writetofile{ans}{\string\begin{multicols}{2}}

只是在第一个解决方案(简短的解决方案)之前

\Writetofile{ans}{\string\end{multicols}} 

最后一个之后

\documentclass[12pt,a4paper]{book}
\usepackage{enumitem,calc}
\setlist[enumerate]{labelsep=10pt,leftmargin=45pt}
\setlist[enumerate,1]{label= $\arabic*.$}
\setlist[enumerate,2]{leftmargin=*,label=\theenumi$\arabic*$),ref=\theenumi$\arabic*$)}
\usepackage{amsmath,amsthm,amssymb}
\newtheorem{exer}{Exercise}[section]
\usepackage{answers}
\Newassociation{solution}{Solution}{ans}
\renewcommand{\Solutionlabel}[1]{#1}
\usepackage{multicol}

\newenvironment{mtmulticols}[1]{%
\Writetofile{ans}{\string\begin{multicols}{#1}}
\begin{multicols}{#1}}{\end{multicols}%
\Writetofile{ans}{\string\end{multicols}}}

\begin{document}
\Opensolutionfile{ans}[exer1.1]
\begin{exer}\label{exer1.1}\mbox{ }
\begin{enumerate}
    \item First problem
    \begin{solution}
    Sol. of first problem
    \end{solution} 
    \item Second problem
\begin{enumerate}
\begin{mtmulticols}{2}
    \item Sub second problem
    \begin{solution}
        Sol. of 2.1
    \end{solution} 
    \item Sub second problem
    \begin{solution}
        Sol. of 2.2
    \end{solution}  
    \item Sub second problem
    \begin{solution}
        Sol. of 2.3
    \end{solution} 
    \item Sub second problem
    \begin{solution}
        Sol. of 2.4
    \end{solution}  
\end{mtmulticols}     
\end{enumerate} 

    \item problem in one column very very very very very long

\Writetofile{ans}{\string\begin{multicols}{2}}
    \begin{solution}
       short  Sol. to very long
    \end{solution}

    \item last problem in one column very very very very very long


    \begin{solution}
       short  Sol. to very long
    \end{solution}
\Writetofile{ans}{\string\end{multicols}}
\end{enumerate}
\end{exer}
\Closesolutionfile{ans}

\bigskip

\section*{\centering Solutions of Chapter \thechapter}

\subsection*{Solutions of Exercise \ref{exer1.1}}
\input{exer1.1}
\end{document}

在此处输入图片描述

相关内容