2

I want to use multicol package in answers package for my text book. How can I fix this problem?

\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}
  • What is the problem? – touhami Jul 4 '15 at 9:05
  • you want solutions output like problemes? – touhami Jul 4 '15 at 9:08
3

If I understand you should add multicols environment to your answers file, here the mtmulticols environment is defined to do this

Edit: Updated the idea is to input

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

just befor first solution (short ones) and

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

after the last one

\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}

enter image description here

  • If the questions in subitems have longer than two columns but the solutions are short, may be for each questions in one column but solutions in two columns? – somkiat_t Jul 4 '15 at 10:10
  • @somkiat_t answer updated – touhami Jul 4 '15 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.