# List enumerated with multi-line stuff inside a minipage

I have created a list using enumitem package. The items of the list should be enumerated with multi-line blocks of text, like this

As I haven't found a way to pass item more than one argument I just pass a minipage. The problem is with the alignement:

I want the text to be aligned with the word "Problem", i. e. blue line to be aligned with the red one. But passing [t] argument to the minipage gives me errors.

UPDATE. After passing [t] option to minipage the next line of the item is to low and a space is added before the first letter:

Here is my MWE

    \documentclass[10pt]{article}

\usepackage[margin=1in]{geometry}

\usepackage{enumitem}

\usepackage{mathtools}

\usepackage{xparse}
\usepackage{lipsum}

%\usepackage{lua-visual-debug} %uncomment to test if everything us ok (requires Lua)

\newcounter{problemscounter}

\newlength{\LABELWIDTH}

\newenvironment{problems}{
\begin{list}{}%
{
\usecounter{problemscounter}
\setlength{\labelwidth}{3cm}
\setlength{\LABELWIDTH}{\labelwidth}
\setlength{\labelsep}{0.5em}
\setlength{\leftmargin}{\labelwidth+\labelsep}
\setlength{\itemsep}{12pt}
\setlength{\listparindent}{1em}
\setlength{\parsep}{1pt}
\setlength{\topsep}{6pt}
}
}{
\end{list}
}

\NewDocumentCommand{\TT}{mmm}{
\item[{%
\begin{minipage}[t]{\LABELWIDTH}
\textbf{%
\textup{%
Problem\kern.4em\ignorespaces\stepcounter{problemscounter}\arabic{problemscounter}.%
}%
}\\
\textit{#1 point#2}.\\%
#3.
\end{minipage}
}]%
}

\begin{document}

\begin{problems}

\TT{1}{}{Mandatory} \lipsum[1]

\TT{2}{s}{Mandatory} More difficult one.

\TT{2017}{s}{Bonus} Good luck solving this.

\end{problems}

\end{document}

• Does it have to be a list or may I change something? – TeXnician May 26 '17 at 15:31
• @TeXnician you want to make a tabular? – Michael Fraiman May 26 '17 at 15:32
• Actually not, although this would be another option, I would mess with minipages only. – TeXnician May 26 '17 at 15:33
• @TeXnician It doesn't need to be list, really. I just want it to look like this and to be "splittable" over pages (not like tabular). – Michael Fraiman May 26 '17 at 15:34
• You need to \smash the tag, as in \NewDocumentCommand{\TT}{mmm}{ \item[{\smash{...}]} – Steven B. Segletes May 26 '17 at 15:39

You can use the list as you had it (although I added some missing %) but hide the height of the minipage. Then to avoid the three line item label overprinting when the paragraph is short, check \prevgraf (the number of lines) at the end of the paragraph and add one or two blank lines if needed.

\documentclass[10pt]{article}

\usepackage[margin=1in]{geometry}

\usepackage{enumitem}

\usepackage{mathtools}

\usepackage{xparse}
\usepackage{lipsum}

%\usepackage{lua-visual-debug} %uncomment to test if everything us ok (requires Lua)

\newcounter{problemscounter}

\newlength{\LABELWIDTH}

\newenvironment{problems}{%
\begin{list}{}%
{%
\usecounter{problemscounter}%
\setlength{\labelwidth}{3cm}%
\setlength{\LABELWIDTH}{\labelwidth}%
\setlength{\labelsep}{0.5em}%
\setlength{\leftmargin}{\labelwidth+\labelsep}%
\setlength{\itemsep}{12pt}%
\setlength{\listparindent}{1em}%
\setlength{\parsep}{1pt}%
\setlength{\topsep}{6pt}%
}%
}{%
\par
\end{list}%
}

\NewDocumentCommand{\TT}{mmm}{%
\par
\item[{%
\begin{minipage}[t][0pt]{\LABELWIDTH}%
\textbf{%
\textup{%
Problem\kern.4em\ignorespaces\stepcounter{problemscounter}\arabic{problemscounter}.%
}%
}\\%
\textit{#1 point#2}.\\%
#3.%
\end{minipage}%
}]%
\everypar\expandafter{\the\everypar
\let\svpar\par
\let\par\TTpar}%
}%

\newcommand\TTpar{%
\let\par\svpar
\par
\ifcase\prevgraf
\or%0
\mbox{}\\*\mbox{}\par\or%1
\mbox{}\par
\fi}

\begin{document}

\begin{problems}

\TT{1}{}{Mandatory} \lipsum[1]

\TT{2}{s}{Mandatory} More difficult one.

\TT{2017}{s}{Bonus} Good luck solving this.

\end{problems}

\end{document}

• Tricy solution, but very good. Your code, in fact, has some strange stiff after \end{document}. I guess it is not needed. – Michael Fraiman May 27 '17 at 20:26
• fortunately, nothing after the end is read, so it is a working code) – Michael Fraiman May 27 '17 at 20:31
• @MichaelFreimann fixed now:-) – David Carlisle May 27 '17 at 20:31

Wrap it into braces. Using braces you can even use optional arguments (which would end the optional argument of \item the other way). Then your approach with t works.

Background: If you want to use \item it scans for an optional argument started with [ and ended with ]. That means if you put a minipage in there that uses [t] item's scan for a closing bracket says HERE and ends the optional item. It should be clear that this is neither intended not able to work. Braces on the other hand form a group that can "mask" such bad characters, what enables optional arguments in optional arguments.

\documentclass[10pt]{scrartcl}

\usepackage[margin=1in]{geometry}

\usepackage{enumitem}

\usepackage{mathtools}

\usepackage{xparse}

%\usepackage{lua-visual-debug} %uncomment to test if everything is ok (requires Lua)

\newcounter{problemscounter}

\newlength{\LABELWIDTH}

\newenvironment{problems}{
\begin{list}{}%
{
\usecounter{problemscounter}
\setlength{\labelwidth}{3cm}
\setlength{\LABELWIDTH}{\labelwidth} %Will be passed to minipage
\setlength{\labelsep}{0.5em}
\setlength{\leftmargin}{\labelwidth+\labelsep}
\setlength{\itemsep}{12pt}
\setlength{\listparindent}{1em}
\setlength{\parsep}{1pt}
\setlength{\topsep}{6pt}
}
}{
\end{list}
}

\NewDocumentCommand{\TT}{mmm}{
\item[{%
\begin{minipage}[t]{\LABELWIDTH}
\textbf{%
\textup{%
Problem\kern.4em\ignorespaces\stepcounter{problemscounter}\arabic{problemscounter}.%
}%
}\\
\textit{#1 point#2}.\\%
#3.
\end{minipage}
}]%
}

\begin{document}

\begin{problems}

\TT{1}{}{Mandatory} The first problem.

\TT{2}{s}{Mandatory} More difficult one.

\TT{2017}{s}{Bonus} Good luck solving this.

\end{problems}

\end{document}


Update 1: A solution completely without environment, but with one additional parameter.

\documentclass[10pt]{article}

\usepackage[margin=1in]{geometry}

\usepackage{enumitem}
\usepackage{mathtools}

\usepackage{xparse}
\usepackage{lipsum}

\newcounter{problemscounter}

\newlength{\LABELWIDTH}
\setlength{\LABELWIDTH}{3cm}
\newlength{\LABELSEP}
\setlength{\LABELSEP}{.5em}

\NewDocumentCommand{\TT}{mmm +m}{
\begin{minipage}[t]{\LABELWIDTH}
\textbf{%
\textup{%
Problem\kern.4em\ignorespaces\stepcounter{problemscounter}\arabic{problemscounter}.%
}%
}\\
\textit{#1 point#2}.\\%
#3.
\end{minipage}\hfill
\begin{minipage}[t]{\dimexpr\textwidth-\LABELWIDTH-\LABELSEP}\setlength{\parindent}{1em}\setlength{\parskip}{1pt}
#4
\end{minipage}\par\vskip12pt
}

\begin{document}

\TT{1}{}{Mandatory}{\lipsum[1]}

\TT{2}{s}{Mandatory}{More difficult one.}

\TT{2017}{s}{Bonus}{Good luck solving this.}
\TT{1}{}{Mandatory}{\lipsum[1]}
\TT{1}{}{Mandatory}{\lipsum[1]}
\TT{1}{}{Mandatory}{\lipsum[1]}
\TT{1}{}{Mandatory}{\lipsum[1]}
\TT{1}{}{Mandatory}{\lipsum[1]}

\end{document}


Update 2: Another approach to think of is using ltablex or similar, which allow automatic text width columns (likep{3cm}X) and page breaking. I won't elaborate on this, because it's a very tricky approach. I would recommend the non-list version.

• It works, thx. Can you please explain why does this happed? – Michael Fraiman May 26 '17 at 15:17
• I haven't properly researched the question, thus a new spacing problem appeared. I have updated the question. – Michael Fraiman May 26 '17 at 15:26
• the new one is good, though minipage cannot split over pages, unfortunately. If you do \TT{1}{}{Mandatory}{\lipsum[1-15]} it causes a bad output. I hope I will not be using such long texts. – Michael Fraiman May 26 '17 at 15:51
• @MichaelFreimann Well hanging also doesn't work. It's currently the best that I can do. – TeXnician May 26 '17 at 15:57
• well, thanks a lot, I will stick with this one for now. – Michael Fraiman May 26 '17 at 15:58

As discussed in comments, the list making environment has issues depending on whether the label is higher (deeper) or shorter than the item body. Fixing one way breaks the other way,e tc. Thus, here I adopt a tabular approach.

I also use stacks instead of a minipage to construct the label. I wrap it all in the original problems environment proposed by the OP. However, instead of using \item, instead set it up like a tabular, as follows:

\begin{problems}
\TT{1}{Mandatory} &\lipsum[1]\par\lipsum[2]\\
\TT{2}{Mandatory} & More difficult one.\\
\TT{2017}{Bonus} & Good luck solving this.
\end{problems}


Finally, I eliminate the need to specify the suffix on "point". I just check to see if the value equals 1; if not, I add an "s" suffix.

EDITED to use longtable in support of page breaks.

\documentclass[10pt]{article}

\usepackage[margin=1in]{geometry}

\usepackage{enumitem}

\usepackage{mathtools}

\usepackage{xparse}
\usepackage[nopar]{lipsum}
\usepackage[usestackEOL]{stackengine}
\usepackage{tabularx,longtable}
%\usepackage{lua-visual-debug} %uncomment to test if everything us ok (requires Lua)

\newcounter{problemscounter}

\newlength{\LABELWIDTH}
\setlength{\LABELWIDTH}{3cm}
\newenvironment{problems}{\noindent\renewcommand\arraystretch{2}%
\begin{longtable}{c>{\parskip 1ex}p{\dimexpr\textwidth-\LABELWIDTH}}
}{
\end{longtable}
}

\NewDocumentCommand{\TT}{mm}{\stepcounter{problemscounter}%
{\Longunderstack[l]{%
\textbf{\textup{Problem\kern.4em\arabic{problemscounter}.}}\\
\textit{#1 point\ifnum#1=1\relax\else s\fi}.\\%
#2.}
}%
}
\newcommand\skipline{\vspace{\baselineskip}}

\newcommand\skiplines{\vspace{2\baselineskip}}

\begin{document}

\begin{problems}
\TT{1}{Mandatory} &\lipsum[1]\par\lipsum[2]\\
\TT{2}{Mandatory} & More difficult one.\\
\TT{2017}{Bonus} & Good luck solving this.\\
\TT{1000}{Ausgezeichnet} & Testing page breaks.
\lipsum[3-5]\\
\TT{2000}{Ausgezeichnet} & Testing page breaks.
\lipsum[4-6]
\end{problems}

\end{document}


• Does it page breaking as the OP wants? – TeXnician May 27 '17 at 8:08
• @TeXnician No it does not...I did not see that requirement. Perhaps I can get around to making it a longtable. – Steven B. Segletes May 27 '17 at 13:38
• Good luck. I tried that (to be fair with ltablex and one X column) and it was disastrous. Hopefully yours will work. – TeXnician May 27 '17 at 15:48
• @TeXnician Added \usepackage{longtable} and changed tabular to longtable and everything worked. Which is to say an overrunning row will break completely to the next page, though a row itself will not be broken up. – Steven B. Segletes May 27 '17 at 19:22