6

For some reason, if one sets a margin using the geometry package, this causes an alignment problem with the tasks package:

MWE:

enter image description here

\documentclass[12pt]{article}

\usepackage{amsmath,geometry,tasks}
\geometry{a4paper, margin=2cm}
\NewTasks[counter-format={tsk[a])}]{problems}[\item](4)

\begin{document}\raggedright

\begin{enumerate}
    \item Prove the following:
    \begin{problems}(4)
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \end{problems}
    \end{enumerate}

\end{document}

Interestingly, at certain values, e.g. margin = 1in, there is no problem. But at other values, such as margin = 0.5cm, which is smaller than a 1in margin, there are problems. This eliminates a minimum width issue. What is the solution to this?

  • 3
    \raggedright does some magic internally, and is being responsible for the issue you see. – Johannes_B Sep 17 '17 at 6:42
  • Is there a way to fix this but maintain raggedright? – Pravin Sep 17 '17 at 6:53
6

One should reset \@rightskip. Imho the tasks package should do it. So make a bug report:

\documentclass[12pt]{article}

\usepackage{amsmath,geometry}
\usepackage{tasks}


\geometry{a4paper, margin=2cm}
\NewTasks[counter-format={tsk[a])}]{problems}[\item](4)

\begin{document}\raggedright

\begin{enumerate}
    \item Prove the following:
    \begingroup
    \makeatletter 
    \@rightskip=0pt
    \begin{problems}(4)
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \item $x$
        \end{problems}
      \endgroup         
    \end{enumerate}

\end{document}
| improve this answer | |
  • 1
    You could use \AtBeginEnvironment{problems}{\setlength\@rightskip{0pt}} (requires etoolbox). – egreg Sep 22 '17 at 9:41
  • I added something to my tracker so I don't forget: github.com/cgnieder/tasks/issues/10 – cgnieder Sep 22 '17 at 13:14
  • Would there be any way to wrap this in an environment? E.g. (with xParse) \NewDocumentEnvironment{dummyEnvironment}{} {\begingroup \makeatletter \@rightskip=0pt \problems(2)} {\endgroup\endproblems} Doesn't work. – Pravin Sep 25 '17 at 5:55
2

Could a solution with \RaggedRight from ragged2e package be acceptable?

EDIT: Ulrike has already given the perfect answer but I'd like to add TeXnician's suggestion (\usepackage[none]{hyphenat}) to my original answer:

\documentclass[12pt]{article}

\usepackage[none]{hyphenat}

\usepackage{amsmath,geometry,tasks}
\geometry{a4paper, margin=2cm}
\NewTasks[counter-format={tsk[a])}]{problems}[\item](4)
\usepackage{ragged2e}

\usepackage{mwe}

\begin{document}\RaggedRight
    \blindtext
    \begin{enumerate}
        \item \blindtext Prove the following:
        \begin{problems}(4)
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
        \end{problems}
    \end{enumerate}
    \blindtext
\end{document}

enter image description here

Moreover, as egreg suggested to me in chat, another simple solution could be justifying only the problems environment:

\documentclass[12pt]{article}

\usepackage{amsmath,geometry,tasks}
\geometry{a4paper, margin=2cm}
\NewTasks[counter-format={tsk[a])}]{problems}[\item](4)
\usepackage{ragged2e}

\usepackage{mwe}

\begin{document}\raggedright
    \blindtext
    \begin{enumerate}
        \item \blindtext Prove the following:
        \begin{justify}
        \begin{problems}(4)
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
            \item $x$
        \end{problems}
        \end{justify}
    \end{enumerate}
    \blindtext
\end{document}

The output is more or less the same as before:

enter image description here

| improve this answer | |
  • Problem is the hyphenation that occurs with that. If there is a way around that, we might have a solution! – Pravin Sep 22 '17 at 8:11
  • Hi! Please leave it up, someone else might know how to fix the hyphenation problem. – Pravin Sep 22 '17 at 8:16
  • But that is pretty close anyway, thanks very much! – Pravin Sep 22 '17 at 8:17
  • 2
    For hyphenation tex.stackexchange.com/questions/5036/… could help. – TeXnician Sep 22 '17 at 8:56
  • @Pravin See the link TeXnician posted – CarLaTeX Sep 22 '17 at 8:59

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.