Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This a follow-up on my previous question Using `environ` to make a list of environments?

Eventually I ended up with the following code using tocloft. I have tried to make it a MWE.

\documentclass[11pt]{scrartcl}

\usepackage{amsmath, amsthm}
%% Begin question thingies
\usepackage{tocloft} % http://ctan.org/pkg/tocloft
\newtheorem{xquestion}{Question}
\newtheorem{xquestionu}[xquestion]{Question (unanswered)}
\newtheorem{xremark}[xquestion]{Remark}
\newcommand\listxquestionsname{List of Remarks and Questions}
\newlistof{questionsandremarks}{qlist}{\listxquestionsname}
% Add the answered questions
\newcommand\qdescription[1]{%
  \addcontentsline{qlist}{questionsandremarks}%
    {\protect\makebox[2.5em][l]{{Q.}~\hfill\thexquestion\hspace{12pt}}#1}}
% Add the unanswered questions
\newcommand\qdescriptionu[1]{%
  \addcontentsline{qlist}{questionsandremarks}%
    {\protect\makebox[2.5em][l]{\textit{{Q.}}~\hfill\thexquestionu\hspace{12pt}}#1}}
% Add the remarks
\newcommand\raddlist{%
  \addcontentsline{qlist}{questionsandremarks}%
    {\protect\makebox[2.5em][l]{{R.}~\hfill\thexremark\hspace{12pt}}}}
\newenvironment{question}[1][]{\begin{xquestion}\qdescription{#1}}{\end{xquestion}}
\newenvironment{questionu}[1][]{\begin{xquestionu}\qdescriptionu{#1}}{\end{xquestionu}}
\newenvironment{remark}{\begin{xremark}\raddlist}{\end{xremark}}
\setlength{\cftafterqlisttitleskip}{\parskip}
\renewcommand{\cftafterqlisttitle}{\\[\baselineskip] A cursive \textit{Q} means that this entry is about a question that is not (yet) answered in the text.}
%% End question thingies

\begin{document}
\begin{questionu}[A test]
Here is my question.
\end{questionu}

\begin{remark}
I also like to make remarks!
\end{remark}
\end{document}

I believe there are some issues with the number which is not properly aligned. How can I fix that?

So, now my question: is this good practice or am I doing it wrong? Furthermore, a bigger problem is the numbering of \thex.... They don't seem to be properly aligned. How do I change the dotted line to say something else (perhaps nothing)? Hitting me with good code hygiene is more than welcome as well! Furthermore, how do I properly wrap the description if it becomes longer than a line?

share|improve this question

1 Answer 1

up vote 4 down vote accepted
  1. To correct the alignment of the counters, you can move the \hspace outside the \makebox.
  2. To suppress the dots you can redefine \cftquestionsandremarksdotsep to be \cftnodots.
  3. I would suggest to control the \makeboxes width and the value for the horizontal space after them, by using defined lengths; in that way, a unique change will assure consistency for the three entry types.
  4. Using \cftsetindents you can control the indentation for the entries.

    \documentclass[11pt]{scrartcl}
    \usepackage{amsmath, amsthm}
    \usepackage{tocloft}
    
    %% Begin question thingies
    \newtheorem{xquestion}{Question}
    \newtheorem{xquestionu}[xquestion]{Question (unanswered)}
    \newtheorem{xremark}[xquestion]{Remark}
    
    \newcommand\listxquestionsname{List of Remarks and Questions}
    \newlistof{questionsandremarks}{qlist}{\listxquestionsname}
    
    % Add the answered questions
    
    \newlength\Labelwidth
    \newlength\AfterLabelspace
    \setlength\Labelwidth{2em}
    \setlength\AfterLabelspace{10pt}
    
    \newcommand\qdescription[1]{%
      \addcontentsline{qlist}{questionsandremarks}%
        {\protect\makebox[\Labelwidth]{Q.\hfill\thexquestion}%
           \protect\makebox[\AfterLabelspace]{}#1}}
    % Add the unanswered questions
    \newcommand\qdescriptionu[1]{%
      \addcontentsline{qlist}{questionsandremarks}%
        {\protect\makebox[\Labelwidth]{\textit{Q}.\hfill\thexquestion}%
           \hspace{\AfterLabelspace}#1}}
    % Add the remarks
    \newcommand\raddlist{%
      \addcontentsline{qlist}{questionsandremarks}%
        {\protect\makebox[\Labelwidth]{R.\hfill\thexquestion}%
           \hspace{\AfterLabelspace}}}
    
    \newenvironment{question}[1][]{\begin{xquestion}\qdescription{#1}}{\end{xquestion}}
    \newenvironment{questionu}[1][]{\begin{xquestionu}\qdescriptionu{#1}}{\end{xquestionu}}
    \newenvironment{remark}{\begin{xremark}\raddlist}{\end{xremark}}
    
    \setlength{\cftafterqlisttitleskip}{\parskip}
    \renewcommand{\cftafterqlisttitle}{\\[\baselineskip] A cursive \textit{Q} means that this entry is about a question that is not (yet) answered in the text.}
    
    % suppress the dots in the new list
    \renewcommand\cftquestionsandremarksdotsep{\cftnodots}
    % set the proper indentation for the entries
    \cftsetindents{questionsandremarks}{0em}{\dimexpr\Labelwidth+\AfterLabelspace\relax}
    
    %% End question thingies
    
    \begin{document}
    
    \listofquestionsandremarks
    
    \begin{questionu}[A test unanswered question with a description spanning more than one line in the list of remarks and questions]
    Here is my question.
    \end{questionu}
    
    \begin{question}[A test answered question]
    Here is my question.
    \end{question}
    
    \begin{remark}
    I also like to make remarks!
    \end{remark}
    
    \end{document}
    

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.