0

I'm trying to make two odd-numbered lists, one with excercises and the other one with solutions, but the latter should have only 4k+1 odd-numbered items. Example: List of questions: 1) 3) 5) 7) etc List of solutions 1) 5) 9) 13) Which commands should I use??

  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. – Stephen May 28 '17 at 17:12
  • Take a look at the enumitem for a package which gives you control over the appearance of lists such as enumerate. – Skillmon May 28 '17 at 17:15
  • What is k here? And how does (say) having q questions translate into 4k + 1 items? – Werner May 28 '17 at 17:16
  • @Werner I guess he means $k \in \mathbb{N}^+$ (or he wants 4001 odd-numbered items, who knows) – Skillmon May 28 '17 at 17:23
  • Sorry, I'm going to edit my quesiton. – Juani May 28 '17 at 17:44
2

I hope I got your question right. Here is a rather primitive way of accomplishing what I hope you want:

\documentclass[]{article}

\let\itembak\item
\makeatletter
\newcommand{\odditems}[1][2]{%
    \setcounter{\@listctr}{\numexpr1-#1}%
    \renewcommand{\item}[1][]{%
        \addtocounter{\@listctr}{\numexpr#1-1}%
        \ifx\relax##1\relax%
            \itembak%
        \else%
            \itembak[##1]%
        \fi%
    }%
}
\makeatother

\begin{document}
\noindent
first:
\begin{enumerate}
    \odditems
    \item first
    \item second
    \item third
\end{enumerate}
second:
\begin{enumerate}
    \odditems[4]
    \item first
    \item second
    \item third
\end{enumerate}
\end{document}

enter image description here

EDIT: The enumerate is nestable (but in a counter intuitive way):

\begin{enumerate}
    \odditems
    \item first
    \item second
    \item third
        \begin{enumerate}
            \odditems[1]% this second call of \odditems allows the nested use
            \item third.first
            \item third.second
            \item third.third
        \end{enumerate}
    \item fourth
\end{enumerate}
  • @Juani though I am glad that it works and is what you wanted, you should not accept this answer just now. It is (almost) always better to wait a few hours so you might get better answers. – Skillmon May 28 '17 at 17:49
0

The following example provides an automated way of setting questions and answers. (Expandable) calculations are provided by xfp and can be generalised as needed:

enter image description here

\documentclass{article}

\usepackage{xfp}

\newcounter{question}\newcounter{question@}
\newenvironment{questions}
  {\setcounter{question@}{0}%
   \begin{enumerate}
     \let\olditem\item
     \renewcommand{\item}{%
       \setcounter{question}{\fpeval{2*\value{question@}}}\refstepcounter{question}%
       \olditem[\thequestion)]\leavevmode\stepcounter{question@}%
     }}
  {\end{enumerate}}

\newcounter{answer}\newcounter{answer@}
\newenvironment{answers}
  {\setcounter{answer@}{0}%
   \begin{enumerate}
     \let\olditem\item
     \renewcommand{\item}{%
       \setcounter{answer}{\fpeval{4*\value{answer@}}}\refstepcounter{answer}%
       \olditem[\theanswer)]\leavevmode\stepcounter{answer@}%
     }}
  {\end{enumerate}}

\begin{document}

Questions:
\begin{questions}
  \item first
  \item second
  \item third
  \item fourth
\end{questions}

Answers:
\begin{answers}
  \item first
  \item second
  \item third
  \item fourth
\end{answers}

\end{document}

The modification of \item doesn't allow for nesting of other lists within questions or answers.

  • I don't get why you need xfp for that. You could use \addtocounter{answer@}{4} instead of the \fpeval{4*\value{anwer@} (same is true for question). What is the advantage of using the package? – Skillmon May 28 '17 at 18:36
  • 1
    @skillmon True; I reference the fact that with xfp one can generalize the calculation to anything arbitrary. – Werner May 28 '17 at 18:40

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.