1

I'm writing a syllabus for a class for which I created a custom enumerate environment, class, that formats it the way I want. The key is that it automatically adds the word "Class X", where X is the counter. A MWE:

\documentclass{scrartcl}
\usepackage{enumitem}
    \newlist{classes}{enumerate}{1}
    \setlist[classes]{
        label=\textbf{Class \arabic*: },
        labelindent=0pt,
        itemindent=0pt,
        leftmargin=!
        style = multiline,
        labelwidth = 50pt,
        before=\setlength{\listparindent}{-\leftmargin},    
    }
\begin{document}
\section*{Syllabus}
Syllabus description.
\begin{classes}
\subsection*{I. Introduction and framework}
\item foo.
\end{classes}
\end{document}

What I haven't been able to achieve is to add an optional argument to \item to identify is the class will be, say, Theoretical or Practical. Something like

\item[t] theoretical class
\item[p] practical class

The idea is that if the option is specified, then the word "Theoretical" or "Practical" is printed below the label. So the output should look like this:

enter image description here

  • Is the item text supposed to wrap or is it just a one liner? – egreg Oct 9 '15 at 16:14
  • Ideally it would wrap right after "Class X:" – han-tyumi Oct 9 '15 at 16:15
  • I meant the text in place of “this is a theoretical class” – egreg Oct 9 '15 at 16:16
  • Yes, it's suppose to wrap (it will be a paragraph-length description of the class with a nested itemize for readings). – han-tyumi Oct 9 '15 at 16:28
2

A version with [t] or [p] support (wrapped label lines)

\documentclass{scrartcl}
\usepackage{etoolbox}
\usepackage{xparse}
\usepackage{letltxmacro}

\newtoggle{classtoggle}%
\newif\iftheoreticalclass


\usepackage{enumitem}

\newlength{\classcellwidth}
\setlength{\classcellwidth}{60pt}

\DeclareRobustCommand{\theoclass}[1]{%
  \begin{tabular}[t]{p{\classcellwidth}}%
    \textbf{Class \number\value{#1}:}  \tabularnewline
    \bfseries Theoretical
  \end{tabular}%
}

\DeclareRobustCommand{\practicalclass}[1]{%
  \begin{tabular}[t]{p{\classcellwidth}}%
    \textbf{Class \number\value{#1}:}  \tabularnewline
    \bfseries Practical
  \end{tabular}%
}

\DeclareRobustCommand{\defaultclass}[1]{%
  \begin{tabular}[t]{p{\classcellwidth}}%
    \textbf{Class \number\value{#1}:}  \tabularnewline
  \end{tabular}%
}


\makeatletter
\newcommand{\classctr}[1]{\classctrint{#1}}
\newcommand{\classctrint}[1]{%
  \iftoggle{classtoggle}{%
    \iftheoreticalclass%
    \theoclass{#1}%
    \else
    \practicalclass{#1}%
    \fi%
  }{%
    \defaultclass{#1}%
  }%
}
\makeatother

\AddEnumerateCounter*{\classctr}{\classctrint}{40}

    \newlist{classes}{enumerate}{1}
    \setlist[classes]{%
      label=\classctr*,
      labelindent=0pt,
      itemindent=0pt,
      leftmargin=!
      style = multiline,
      labelwidth = 50pt,
      before=\setlength{\listparindent}{-\leftmargin},    
    }

\LetLtxMacro\origitem\item

\RenewDocumentCommand{\item}{o}{%
  \toggletrue{classtoggle}% Switch to use t or p mode temporarily
  \IfValueTF{#1}{%
    \theoreticalclassfalse%
    \ifstrequal{#1}{t}{%
      \theoreticalclasstrue%
      \origitem%
    }{%
      \ifstrequal{#1}{p}{%
        \theoreticalclassfalse%
        \origitem%
      }{% 
        \togglefalse{classtoggle}% No, it's neither p nor t
        \origitem[#1]%
      }%
    }%
  }{%
    \togglefalse{classtoggle}%
    \origitem
  }%
}

\begin{document}
\section*{Syllabus}
Syllabus description.
\begin{classes}
\subsection*{I. Introduction and framework}
\item[p] foo.
\item[t] bar
\item    None
\item[p]    Again
\end{classes}

\begin{enumerate}
\item[t] Test
\end{enumerate}
\end{document}

enter image description here

  • A preliminary version... – user31729 Oct 9 '15 at 16:05
1

I managed to do it by creating a custom \item command, but I think there are probably better solutions. Anyway, this is my attempt:

\documentclass{scrartcl}
\usepackage{enumitem}
\newlist{classes}{enumerate}{1}
\setlist[classes]{
  label=Class \arabic*:\protect\thiscitem,
  style = multiline,
  leftmargin=!,
  labelwidth = 60pt,
}
\newcommand{\citem}[1][]{%
  \if\relax\detokenize{#1}\relax
    \def\thiscitem{}%
  \else
    \def\thiscitem{\\(#1)}%
  \fi
  \item}
\begin{document}
\section*{Syllabus}
Syllabus description.
\begin{classes}
\subsection*{I. Introduction and framework}
\citem[Theoretical] foo.
\end{classes}
\end{document}

enter image description here

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.