我有以下用于生成课程提纲日期的自定义列表:
\documentclass{article}
\usepackage{advdate}
\usepackage[dayofweek]{datetime}
\newdateformat{syldate}{\twodigit{\THEMONTH}/\twodigit{\THEDAY}
\,(\shortdayofweekname
{\THEDAY}{\THEMONTH}{\THEYEAR})}
\newenvironment{schedule}
{\par\syldate\renewcommand{\item}{\par
\stepcounter{mycntr}\ifnum\value{mycntr}>2\relax
\setcounter{mycntr}{0}\AdvanceDate[3]
\else
\AdvanceDate[2]
\fi\today\quad}
}{\par}
\SetDate[01/09/2014]
\newcounter{mycntr}
\begin{document}
\begin{schedule} % My custom environment with problematic behavior
\item Topic \\ Assigned Reading
\item Topic \\ Assigned Reading
\end{schedule}
\begin{itemize} % Desired behavior
\item Topic \\ Assigned Reading
\item Topic \\ Assigned Reading
\end{itemize}
\end{document}
每当我尝试将项目的第二部分移到新行时,它都会与项目标签对齐,而不是与项目的第一行对齐。Itemize 默认会执行我想要的操作。如何将这种行为构建到我的自定义列表中?
答案1
如果你不打算在“指定阅读材料”中列出清单和段落,你可以选择
\documentclass{article}
\usepackage{advdate}
\usepackage[dayofweek]{datetime}
\newdateformat{syldate}{%
\twodigit{\THEMONTH}/\twodigit{\THEDAY}%
\,(\shortdayofweekname
{\THEDAY}{\THEMONTH}{\THEYEAR})%
}
\newlength{\datelength}
\newenvironment{schedule}
{\par
\settowidth{\datelength}{00/00\,(Wed)\quad}%
\renewcommand{\item}{%
\par\hangindent=\datelength\noindent
\stepcounter{mycntr}\ifnum\value{mycntr}>2\relax
\setcounter{mycntr}{0}\AdvanceDate[3]%
\else
\AdvanceDate[2]%
\fi
\makebox[\datelength][l]{\today}%
}%
\syldate
}
{\par}
\SetDate[01/09/2014]
\newcounter{mycntr}
\begin{document}
\begin{schedule} % My custom environment with problematic behavior
\item Topic \\ Assigned Reading
\item Topic \\ Assigned Reading
\item Topic \\ Assigned Reading
\item Topic \\ Assigned Reading
\end{schedule}
\end{document}
然而,更好的实现是enumitem
:
\documentclass{article}
\usepackage{showframe} % just for the example
\usepackage{enumitem}
\usepackage{advdate}
\usepackage[dayofweek]{datetime}
\newdateformat{syldate}{%
\twodigit{\THEMONTH}/\twodigit{\THEDAY}%
\,(\shortdayofweekname
{\THEDAY}{\THEMONTH}{\THEYEAR})%
}
\newlength{\datelength}
\newcommand\topic[1]{%
\stepcounter{mycntr}%
\ifnum\value{mycntr}>2\relax
\setcounter{mycntr}{0}\AdvanceDate[3]%
\else
\AdvanceDate[2]%
\fi
\item[\today]#1\\
}
\newenvironment{schedule}
{\syldate
\settowidth{\datelength}{00/00\,(Wed)\quad}%
\enumerate[leftmargin=\datelength,labelsep=0pt,labelwidth=\datelength,align=left]
}
{\endenumerate}
\SetDate[01/09/2014]
\newcounter{mycntr}
\begin{document}
\begin{schedule}
\topic{Topic} Assigned Reading
\topic{Topic} Assigned Reading
\topic{Topic} Assigned Reading
\topic{Topic} Assigned Reading
\end{schedule}
\end{document}
我更喜欢使用\topic
命令而不是滥用,\item
这样只需根据定义采取行动就可以随意定制主题标题的外观\topic
。
垂直间距可通过功能进行自定义enumitem
。请注意,showframe
此处使用的 仅用于显示文本块边距。
答案2
缩进的差异源于第一行缩进是由于\parindent
,它不会延续到后续行。将缩进延续到后续行的参数是\leftskip
。我会大大重写该方法(也许使用list
环境,但为了快速实现您的要求,我只是插入了这一行
\leftskip=\parindent\relax\parindent=0pt\relax
在环境的开头schedule
。它的作用是使用当前值\parindent
作为\leftskip
环境调用的当前值。
\documentclass{article}
\usepackage{advdate}
\usepackage[dayofweek]{datetime}
\newdateformat{syldate}{\twodigit{\THEMONTH}/\twodigit{\THEDAY}
\,(\shortdayofweekname
{\THEDAY}{\THEMONTH}{\THEYEAR})}
\newenvironment{schedule}
{\leftskip=\parindent\relax\parindent=0pt\relax
\par\syldate\renewcommand{\item}{\par
\stepcounter{mycntr}\ifnum\value{mycntr}>2\relax
\setcounter{mycntr}{0}\AdvanceDate[3]
\else
\AdvanceDate[2]
\fi\today\quad}
}{\par}
\SetDate[01/09/2014]
\newcounter{mycntr}
\begin{document}
\begin{schedule} % My custom environment with problematic behavior
\item Topic \\ Assigned Reading
\item Topic \\ Assigned Reading
\end{schedule}
\begin{itemize} % Desired behavior
\item Topic \\ Assigned Reading
\item Topic \\ Assigned Reading
\end{itemize}
\end{document}
请注意,您设置的方式是,schedule
环境缩进的值\parindent
。在我的 MWE 中,可以通过将的值设置\leftskip
为 0pt 而不是 来删除它\parindent
。