1

I want to align the question options to the width of the column enter image description here Like this:

enter image description here

\documentclass[a4paper,9pt]{extarticle}
\usepackage[margin=1.5cm]{geometry}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{tasks}
\usepackage{multicol}
\usepackage{enumitem}
\newlength{\taskindent}
\settowidth{\taskindent}{\hspace{0.09cm}\text{m)}}
\settasks{
    item-indent=\taskindent,
    label-format=\MakeUppercase, 
    after-skip = 3ex,
}

\begin{document}
\begin{multicols*}{2}
\begin{enumerate}[left=0pt,label=\bfseries\arabic*.,ref=\arabic*,resume]
\item 
\begin{justify}
        \textbf{I want to align options to width but not aligned as seen} 
\end{justify}
\begin{tasks}(5)
                \task $1$
                \task $2$
                \task $3$
                \task $4$
                \task $5$
            \end{tasks}
\end{enumerate}
\vfill\null
\columnbreak

\begin{enumerate}[left=0pt,label=\bfseries\arabic*.,ref=\arabic*,resume]
\item 
\begin{justify}
        \textbf{I want to align options to width but not aligned as seen} 
\end{justify}
\begin{tasks}(5)
                \task $1$
                \task $2$
                \task $3$
                \task $4$
                \task $5$
            \end{tasks}
\end{enumerate}
\end{multicols*}
\end{document}

2 Answers 2

2

tasks package will typeset each item in a fixed-with box, like

<tasks>    ::= <fwd-item> (<item-sep> <fwd-item>)*
<fwd-item> ::= \hbox to <some-fixed-width>{<item>}

hence changing it to

<tasks>.   ::= <item> (\hfill <item>)*

requires considerable patching.

But you can simulate the desired effect by picking an appropriate value for column-set=<length>, as far as the remaining line width (divided by the number of items per line) is wide enough to typeset each item text. For example, with column-sep=3em (and debug to draw bounding boxes),

\documentclass[a4paper,9pt]{extarticle}
\usepackage[margin=1.5cm]{geometry}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{tasks}
\usepackage{multicol}
\usepackage{enumitem}
\newlength{\taskindent}
\settowidth{\taskindent}{\hspace{0.09cm}\text{m)}}
\settasks{
    item-indent=\taskindent,
    label-format=\MakeUppercase, 
    after-skip = 3ex,
    debug
}

\begin{document}
\begin{multicols*}{2}
Default:
\begin{enumerate}[left=0pt,label=\bfseries\arabic*.,ref=\arabic*,resume]
\item 
  \textbf{I want to align options to width but not aligned as seen} 
\begin{tasks}(5)
    \task $1$
    \task $2$
    \task $3$
    \task $4$
    \task $5$
\end{tasks}

\settasks{column-sep=3em}%
Setting \verb|column-sep=3em|:

\item 
  \textbf{I want to align options to width but not aligned as seen} 
\begin{tasks}(5)
    \task $1$
    \task $2$
    \task $3$
    \task $4$
    \task $5$
\end{tasks}
\end{enumerate}
\end{multicols*}
\end{document}

enter image description here

Compared to @CarLaTeX's answer which uses itemjoin and inline list envs from enumitem package,

  • When the width of item text changes (but still fit in the allowed max width of an item), tasks ensures items in different multi-choice questions vertically aligned, while inline list envs don't have this feature.
  • When the width of item text is large enough, tasks will wrap the text in lines by the width of item width, while inline list envs will wrap the whole list by the width of line width.
7
  • It partially worked for me, thank you. Can we enter a generic column-sep value? affecting the entire document? So that automatically aligns the options to the column width? @muzimuzhi Z
    – Pitaya88
    Commented Nov 12, 2021 at 7:41
  • @Pitaya88 Sure, you can set column-sep globally like how you set item-indent and the similar. Commented Nov 12, 2021 at 7:45
  • How? I tried but it goes beyond the width @muzimuzhi Z
    – Pitaya88
    Commented Nov 12, 2021 at 7:51
  • 1
    Add column-sep=<length> to your existing \settasks{ item-indent=\taskindent, label-format=\MakeUppercase, after-skip = 3ex, } Commented Nov 12, 2021 at 8:00
  • 1
    Correct me if I misunderstood "enter a generic column-sep value". Commented Nov 12, 2021 at 8:01
3

You may use enumerate* from enumitem package:

\documentclass[a4paper,9pt]{extarticle}
\usepackage[margin=1.5cm]{geometry}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{multicol}
\usepackage[inline]{enumitem}

\begin{document}
\begin{multicols*}{2}
\begin{enumerate}[left=0pt,label=\bfseries\arabic*.,ref=\arabic*,resume]
\item \bfseries I want to align options to width but not aligned as seen

    \begin{enumerate*}[before*={\noindent},label=\Alph*), font=\normalfont,itemjoin=\hfill]
                    \item $1$
                    \item $2$
                    \item $3$
                    \item $4$
                    \item $5$
    \end{enumerate*}
\end{enumerate}
\vfill\null
\columnbreak
\begin{enumerate}[left=0pt,label=\bfseries\arabic*.,ref=\arabic*,resume]
\item \bfseries I want to align options to width but not aligned as seen

    \begin{enumerate*}[before*={\noindent},label=\Alph*), font=\normalfont,itemjoin=\hfill]
                    \item $1$
                    \item $2$
                    \item $3$
                    \item $4$
                    \item $5$
    \end{enumerate*}
\end{enumerate}
\end{multicols*}
\end{document}

enter image description here

If your lists are always like that you can set them with \setlist[enumerate,<levels>]{<format>}.

You must log in to answer this question.

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