2

Consider the following example.

\documentclass{article}

\usepackage{enumitem}

% New line after \item (http://tex.stackexchange.com/a/29518/15874)
\makeatletter
\def\myitem{%
  \@ifnextchar[ \@myitem{\@noitemargtrue\@myitem[\@itemlabel]}}
  \def\@myitem[#1]{\item[#1]\mbox{}\\}
\makeatother
% Exercise
\setlist[enumerate,1]{
  wide = 0\parindent,
  listparindent = 0pt,
  label = \textbf{Exercise~\arabic*}
}
% Question
\setlist[enumerate,2]{
  wide = 0\parindent,
  listparindent = 0pt,
  label = \textbf{\alph*)}
}

\begin{document}

\begin{enumerate}
\myitem
  \begin{enumerate}
    \item A
    \item B
  \end{enumerate}
\end{enumerate}

\end{document}

output

How do I

  • remove the blank space after Exercise?
  • get rid of the Underfull \hbox warning (do to the blank line after Exercise)? P.S. I don't want any text between Exercise and a).
  • I think, the `\\ ` screws the spacing up ;-) – user31729 Jun 9 '15 at 19:55
  • @ChristianHupfer That was too 'easy'; I should have figured that out myself. :) Thanks. – Svend Tveskæg Jun 9 '15 at 20:11
  • @SvendTveskæg If you want to start from a new line (which is what \mbox{}\\ achieves) you can use enumitem keys for the occasion, see 3.7 Description styles in the documentation. – Manuel Jun 9 '15 at 20:35
  • @Manuel I might (read: probably) miss something obvious but I can't figure out which options to use. I think that I've tried all of them without succes. If I can make you give an answer with this behaviour, I will very much appreciate it. – Svend Tveskæg Jun 9 '15 at 20:41
  • 1
    @SvendTveskæg I slipped, probably. That only works for description-like environments, and you are using enumerate. – Manuel Jun 9 '15 at 21:33
6

In the following line

\def\@myitem[#1]{\item[#1]\mbox{}\\}

you have \\ which creates another line. Remove it to remove the blank space. If you want to further reduce the space you can add a negative vertical space. Here's the two versions.

Output

Added \vspace{-1ex}

enter image description here

Empty

enter image description here

Code

\documentclass{article}

\usepackage{enumitem}

% New line after \item (http://tex.stackexchange.com/a/29518/15874)
\makeatletter
\def\myitem{%
  \@ifnextchar[ \@myitem{\@noitemargtrue\@myitem[\@itemlabel]}}
  \def\@myitem[#1]{\item[#1]\mbox{}\vspace{-1ex}}
\makeatother
% Exercise
\setlist[enumerate,1]{
  wide = 0\parindent,
  listparindent = 0pt,
  label = \textbf{Exercise~\arabic*},
  %partopsep=-40ex
}
% Question
\setlist[enumerate,2]{
  wide = 0\parindent,
  listparindent = 0pt,
  label = \textbf{\alph*)}
}

\begin{document}

\begin{enumerate}
\myitem
  \begin{enumerate}
    \item A
    \item B
  \end{enumerate}
\end{enumerate}
\end{document}
  • 1
    That was rather 'easy'; I should probably have figured that out myself. :) Thanks. – Svend Tveskæg Jun 9 '15 at 20:11
  • @SvendTveskæg It's fine. :D I often don't see very plain mistakes in my code too. :D – Alenanno Jun 9 '15 at 20:39

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.