5

I'm trying to create a list environment that labels each item in a certain way. Honestly I could just manually do it but I wanted to learn more about the environment creation processes so I tried to do it by hand. Here is the code I used:

\documentclass{amsart}

\newcounter{Week}
\newenvironment{Weeks}
   {\begin{list}{{\Large \bf Week \arabic{Week}:}}%
       {%
         \setlength\labelwidth{.25in}%
         \setlength\leftmargin{0in}%
         \setlength\itemsep{24 pt}%
         \usecounter{Week}}%
       }%
   {%
   \end{list}%
   }%
\begin{document}
\begin{Weeks}
\item This is a test
\item 2nd test
\end{Weeks}
\end{document}

It mostly does what I want, but I wanted to ask if there was a way for me to in addition to listing each line with the label, is it possible to include a line break so that the text you add appears on the next line after the label "Week x:"? I know I could manually just add the line break on each item -- I just want to learn how to do this in another way in the enviorontment definition code.

0

4 Answers 4

3

First, as @ChristianHupfer alredy noted in the comments of the OP, don't use \bf. Alternatively LaTeX defines the analogous \bfseries. Secondly, the fullpage package is also deprecated. geometry is the canonical way to set up the page geometry.

Regarding the solution I recommend to first abstract the formatting of the list labels into an auxiliary macro -- it comes in handy later on:

\newcommand*\marklabel[1]{\bgroup\Large\bfseries#1\egroup}

Then you can define an alternative \item-like macro:

\newcommand*\weekitem[1][]{%
  \expandafter\ltxitem
  \if\relax\detokenize{#1}\relax\else[#1]\fi
  \leavevmode\par\vskip1em\par\noindent
}

(where \ltxitem will be a copy of the default \item macro.)

Note that \weekitem mantains the ability to specify an alternative label by hand via the optional argument. Finally in the list header in the \newenvironment definition you specify that \item should be let to \weekitem:

\newenvironment{Weeks}{%
  \begin{list}{{\marklabel{Week \arabic{Week}}:}}{%
    \setlength\labelwidth{.25in}%
    \setlength\leftmargin{0in}%
    \setlength\itemsep{24pt}%
    \usecounter{Week}%
    \let\ltxitem\item
    \let\item\weekitem}%
}{%
  \end{list}%
}

showcase

Complete Code

\documentclass[11pt]{amsart}
\usepackage{lipsum}

\newcommand*\marklabel[1]{\bgroup\Large\bfseries#1\egroup}
\newcounter{Week}
\newenvironment{Weeks}{%
  \begin{list}{{\marklabel{Week \arabic{Week}}:}}{%
    \setlength\labelwidth{.25in}%
    \setlength\leftmargin{0in}%
    \setlength\itemsep{24pt}%
    \usecounter{Week}%
    \let\ltxitem\item
    \let\item\weekitem}%
}{%
  \end{list}%
}
\newcommand*\weekitem[1][]{%
  \expandafter\ltxitem
  \if\relax\detokenize{#1}\relax\else[#1]\fi
  \leavevmode\par\vskip1em\par\noindent
}

\begin{document}
\begin{Weeks}
  \item This is a test. \lipsum[1]
  \item 2nd test
  \item[\marklabel{Addendum}:] final test
\end{Weeks}
\end{document}
1
  • Oh, may, I did not notice fullpage at all!
    – user31729
    Commented Jan 3, 2017 at 7:41
2

You can change definition of item to add line break after item label

\let\olditem\item
\def\item{\olditem\leavevmode\newline}

Complete code

\documentclass[11pt]{amsart}
\usepackage{geometry}                
%\usepackage[parfill]{parskip}  
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage[empty,in]{fullpage}
\newcounter{Week}
\newenvironment{Weeks}
   {\begin{list}{{\Large \bfseries Week \arabic{Week}:}}%
       {%
         \let\olditem\item
         \def\item{\olditem\leavevmode\newline}
         \setlength\labelwidth{.25in}%
         \setlength\leftmargin{0in}%
         \setlength\itemsep{24 pt}%
         \usecounter{Week}}%
       }%
   {%
   \end{list}%
   }%
\begin{document}


\begin{Weeks}
\item This is a test
\item 2nd test
\end{Weeks}
\end{document}

enter image description here

2

I propose another variant for the Weeks environment, based on enumitem:

\documentclass[11pt]{amsart}
\usepackage{geometry}
\usepackage[parfill]{parskip}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage[empty,in]{fullpage}

\usepackage{enumitem, calc} %
 \newlist{Weeks}{enumerate}{1}
 \setlist[Weeks]{label=\raisebox{0pt}[3.5ex][1.5ex]{\makebox[\textwidth][l]{Week \arabic*}}, font =\Large\bfseries, wide = 0pt, itemsep=24pt, leftmargin=\widthof{\Large\textbf{Week}} }
\usepackage{showframe} %
\renewcommand{\ShowFrameLinethickness}{0.3pt}


\begin{document}

Text text text text

\begin{Weeks}
  \item This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.

  \item 2nd test
\end{Weeks}

\end{document} 

enter image description here

1

Here is a way with enumitem and defining Weeks with a \newlist.

The counter is called Weeksi (autodefined by enumerate)

\documentclass[11pt]{amsart}
\usepackage{geometry}                
%\usepackage[parfill]{parskip}  
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage[empty,in]{fullpage}

\usepackage{enumitem}
\usepackage{xpatch}
\newlist{Weeks}{enumerate}{1}

\AtBeginEnvironment{Weeks}{%\
  \xapptocmd{\item}{%
    \leavevmode\par%
    }{\typeout{Success}}{}
}
\setlist[Weeks,1]{label={\Large \bfseries Week {\arabic*}:},itemsep=24pt, labelwidth=.25in,labelindent=!,listparindent=0em}


\begin{document}

\begin{Weeks}
\item This is a test
\item 2nd test
\item Another Test
\item The \arabic{Weeksi}th Week!
\end{Weeks}
\end{document}

enter image description here

1
  • \item[...] won't work any longer, of course
    – user31729
    Commented Jan 3, 2017 at 1:07

You must log in to answer this question.

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