2

My goal is to have a list with Arabic numbering, with each Arabic number having a sub-list with Latin numbering. Each Arabic-numbered item represents a general category, with each Latin-numbered item representing a question within that category.

After each question, I want to be able to type up the answer. Thus, I attempted this with an enumerate, another enumerate within that, and then whenever I needed to write a paragraph to answer the question, I would end the inner enumerate, write the paragraph, then resume the enumerate once I've completed it. Example below:

\documentclass{article}

\usepackage{enumitem}

\begin{document}
    \begin{enumerate}
        \item{}

        \begin{enumerate}[label=\roman*)]
            \item{Question:}
        \end{enumerate}

        My answer

        \begin{enumerate}[resume,label=\roman*)]
            \item{Question 2:}
        \end{enumerate}

        My second answer
    \end{enumerate}
\end{document}

The issue with this approach is that the answer text is bound to the outer enumerate's indentation. If I was to exit the outer enumerate as well, I would not be able to re-start the enumerate without re-starting the numbering as well, as I cannot seem to use enumerate without a present item.

As an additional note, I am looking to keep the Latin-numbered list items within the indentation whilst allowing the paragraph text to remain un-indented.

What is the best way for me to obtain the desired effect?

1
  • 1
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – BambOo
    Nov 5, 2018 at 16:08

2 Answers 2

2

REVISED ANSWER (using \leftskip)

This revised answer will allow pagebreaks in the middle of the answer.

\documentclass{article}
\usepackage{enumitem,lipsum}
\usepackage[pass,showframe]{geometry}
\newcommand\myanswer[1]{{%
  \leftskip-\dimexpr\leftmargini+\leftmarginii\relax #1\par}}
\begin{document}
\begin{enumerate}
    \item{}

    \begin{enumerate}[label=\roman*),parsep=5pt]
        \item Question: What is the margination if my question
          goes on long enough?

    \myanswer{My answer shows that the answer will retain the
      proper margination if one uses the macro
      \textbackslash myanswer.}
    \end{enumerate}


    \begin{enumerate}[resume,label=\roman*),parsep=5pt]
        \item{Question 2:}

    \myanswer{My second answer}
    \end{enumerate}

    \begin{enumerate}[resume, label=\roman*),parsep=5pt]
        \item{Question 3:}

    \myanswer{My third answer \lipsum[4-8]}
    \end{enumerate}
\end{enumerate}
\end{document}

enter image description here

ORIGINAL ANSWER

Maybe something like this, using listparindent to undo indentation for extra paragraphs of an item. The key here for usage is to

  1. Make the answer part of the same \item that comprises the question.

  2. use \myanswer to typeset your answer, if it is longer than a single line.

The MWE:

\documentclass{article}
\usepackage{enumitem}
\usepackage[pass,showframe]{geometry}
\newcommand\myanswer[1]{\parbox[t]{\textwidth}{#1}}
\begin{document}
\begin{enumerate}
    \item{}

    \begin{enumerate}[label=\roman*),parsep=5pt,
      listparindent=-\dimexpr\leftmargini+\leftmarginii\relax]
        \item Question: What is the margination if my question
          goes on long enough?

    \myanswer{My answer shows that the answer will retain the
      proper margination if one uses the macro
      \textbackslash myanswer.}
    \end{enumerate}


    \begin{enumerate}[resume,label=\roman*),parsep=5pt,
      listparindent=-\dimexpr\leftmargini+\leftmarginii\relax]
        \item{Question 2:}

    \myanswer{My second answer}
    \end{enumerate}

    \begin{enumerate}[resume, label=\roman*),parsep=5pt,
      listparindent=-\dimexpr\leftmargini+\leftmarginii\relax]
        \item{Question 3:}

    \myanswer{My third answer}
    \end{enumerate}
\end{enumerate}
\end{document}

enter image description here

3
  • Is there a way I can get this to break cross pages? Long answers seem to cause the page to overflow.
    – VortixDev
    Nov 5, 2018 at 16:55
  • 1
    @VortixDev As it is currently formulated, no page breaking across an answer, but let me think a bit more. Nov 5, 2018 at 17:00
  • 1
    @VortixDev Please see my revised answer Nov 5, 2018 at 17:06
2

You could use the TeX primitive \parshape to escape the indentation introduced by all list environments. The following should do what you want:

\documentclass{article}

\usepackage{enumitem}
\usepackage{lipsum} %% <- for \lipsum

\makeatletter   %% <- make @ usable in macro names
\newcommand*\answer[1]{%
  \begingroup   %% <- limit scope of the following changes
    \par        %% <- start a new paragraph
    \@totalleftmargin=0pt \linewidth=\columnwidth
    %% ^^ let other commands know that the margins have been reset
    \parshape 0
    %% ^^ reset the margins
    #1\par      %% <- insert #1 and end this paragraph
  \endgroup
}
\makeatother    %% <- revert @

\begin{document}

\lipsum[66]

\begin{enumerate}
\item
    \begin{enumerate}[label=\roman*)]

    \item
        Question 1:
    \answer{\lipsum[75]}

    \item
        Question 2:
    \answer{\lipsum[75]}

    \end{enumerate}
\end{enumerate}

\end{document}

enter image description here

You could alternatively define an answer environment using

\makeatletter %% <- make @ usable in macro names
\newenvironment*{answer}{%
  \par
  \@totalleftmargin=0pt \linewidth=\columnwidth
  \parshape 0
}{\par}
\makeatother %% <- revert @

About \parshape:

Under the hood, all list commands use \parshape to change the margins. Though it can be used to do a lot more, if you just want to change the indentation/width of the current (and all subsequent) paragraphs you can call

\@totalleftmargin=<new indentation> \linewidth=<new line width>
\parshape 1 \@totalleftmargin \linewidth

You could also just write \parshape 1 <new indentation> <new width>, but then other commands (such as the list environments) inside the paragraph won't know what margins you have set (and assume the old values). \parshape 0 undoes the effect of previously issued \parshapes.

2
  • Thanks for the answer! The command works perfectly, though when I try to use the environment, I get "You can't use '/spacefactor' in vertical mode", as well as "Missing $ inserted".
    – VortixDev
    Nov 5, 2018 at 17:05
  • 1
    That's because the definition of the environment, like that of \answer, should be surrounded by \makeatletter and \makeatother (because \@totalleftmargin contains an @). I'll add these. See this answer for more information. Nov 5, 2018 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .