1

I have done this:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath, mathptmx, amssymb}

\usepackage{tasks}[newest]
\settasks{label = \textbf{\Alph*.}}

\usepackage{enumitem}
\setlist[enumerate]{
    label = \textbf{Question \arabic*.},
    ref = \arabic*
}
\newcommand\correct{\label{\theenumi}}

%=========================================================
\begin{document}
\begin{enumerate} 
\item How many letters in the word ``Tea'' ?
    \begin{tasks}(4)
        \task $1$
        \task $3$ \correct
        \task $2$
        \task $4$.
   \end{tasks}
\end{enumerate}
    The answer is \ref{1}.
\end{document}

enter image description here

I intend to automatically label (for example, \label{1} for question 1) and manually refer.

I need "The answer is B" (without bold and dot) in the last line, but remain \ref{1} for later use (as {1} refers to question 1).

It will be helpful if the solution stays on tasks and enumerate environments, because I've already used them for my entire document.

  • The aux file has \newlabel{{1}}{{\textbf {B.}}{1}} which means you need \ref{{1}} – cgnieder Apr 27 '20 at 12:52
  • Also, you might be interested in https://tex.stackexchange.com/questions/498299/ – cgnieder Apr 27 '20 at 12:58
  • @cgnieder Thank for your quick reply, such a simple solution makes it work perfectly. I took a look at the website you've given, it's great and I'll definitely try it later. But currently, is there any direct way to remove bold and dot of \ref{{1}} in my case? – Nguyễn Xuân Duy Bảo Apr 27 '20 at 13:53
  • Yes, separate label and formatting. For example you can define \newcommand*\tasklabelformat[1]{\textbf{#1.}} and then set \settasks{ label = \Alph* , label-format = \tasklabelformat }. BTW: you should also adjust the label-width, check the warnings in the log file. – cgnieder Apr 27 '20 at 14:50

1 Answers1

1

The aux file to you MWE has the following line:

\newlabel{{1}}{{\textbf {B.}}{1}} 

This means that you need to use \ref{{1}} with your approach. However, the reference will then be \textbf {B.} , i.e.. a bold B with a bold dot.

But if you separate formatting and label you get what you want. You could do

\newcommand*\tasklabelformat[1]{\textbf{#1.}}

and then set

\settasks{
  label = \Alph* ,
  label-format = \tasklabelformat
}

enter image description here

A complete example which also sets the label-width according to warings in he log:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath, mathptmx, amssymb}

\newcommand*\tasklabelformat[1]{\textbf{#1.}}

\usepackage{tasks}[newest]
\settasks{
  label = \Alph* ,
  label-format = \tasklabelformat ,
  label-width  = 12pt
}

\usepackage{enumitem}

\setlist[enumerate]{
  label = \textbf{Question \arabic*.},
  ref = \arabic*
}
\newcommand\correct{\label{\theenumi}}

\begin{document}

\begin{enumerate} 
  \item How many letters are in the word ``Tea''?
    \begin{tasks}(4)
      \task $1$
      \task $3$ \correct
      \task $2$
      \task $4$.
   \end{tasks}
\end{enumerate}

The answer is \ref{{1}}.

\end{document}
cgnieder
  • 66,645