在定制的枚举类环境中设置首行缩进

在定制的枚举类环境中设置首行缩进

我想创建一个列表项环境。我不想将这些项作为 的一部分enumerate,因为我希望能够在这些项之间放置任何内容。

到目前为止,我已经取得了相当大的成功,但我正在努力寻找一种方法来控制第一行的开始时间,以便所有项目中的文本开头均对齐

这是我迄今为止的尝试。 在此处输入图片描述

请注意,Task 1每个项目的文本从不同的位置开始,而 中的两个项目的位置相同Task 2我怎样才能实现 Task 2 同时保持语法 Task 1

以下是最小的工作示例:

\documentclass[12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}  % Sets language
\usepackage{geometry}  % To establish the properties of the pages
\usepackage{enumitem}
\usepackage{lipsum}


%% General properties of the pages
\geometry{
 a4paper,
 left = 23mm,
 right = 23mm,
 top = 23mm,
 bottom = 23mm
}
\setlength{\parskip}{0.65em}  % Sets paragraph skip
\setlength{\parindent}{0em}  % No paragraph indentation
\setlist[enumerate]{itemsep=0em,
                    topsep=0.10em,
                    leftmargin=*,
                    label=\textbf{\alph*)}, wide}  % Sets default for enumerate
\frenchspacing  % Just ONE SPACE after the period, not two spaces

% To get letters from numbers
\makeatletter
\newcommand{\makealph}[1]{\@alph{#1}}
\makeatother

% Environment for the rubric of a task.
\newcounter{outercounter}
\newcounter{innercounter}
\newenvironment{rubric}[1]{
    \stepcounter{outercounter}%
    \setcounter{innercounter}{0}%
    \par%
    \begin{sffamily}%
    \textbf{Task \theoutercounter} (#1)\textbf{.}%
}{
    \end{sffamily}%
    \par%
}
% Environment for a rubric item.
\newenvironment{rubricitem}{
    \par%
    \begin{sffamily}%
    \stepcounter{innercounter}%
    \textbf{\makealph{\theinnercounter})}%
}{
    \end{sffamily}%
    \par%
}

\begin{document}
\begin{rubric}{With custom items}
\lipsum[1][1]
\end{rubric}
\begin{rubricitem}
\lipsum[1][2-5]
\end{rubricitem}
\lipsum[1][7-10]
\begin{rubricitem}
\lipsum[1][6]
\end{rubricitem}

\bigskip

\begin{rubric}{With enumerate items}
\lipsum[1][1]
\begin{enumerate}
    \item \lipsum[1][2-5]
    \item \lipsum[1][6]
\end{enumerate}
\end{rubric}
\end{document}

答案1

更新后续问题。在rubricitem环境中,计数器被封装在parbox允许对齐的BODY(s)(包environ)中

d

\documentclass[12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}  % Sets language
\usepackage{geometry}  % To establish the properties of the pages
\usepackage{enumitem}
\usepackage{lipsum}

\usepackage{xcolor}

%% General properties of the pages
\geometry{
    a4paper,
    left = 23mm,
    right = 23mm,
    top = 23mm,
    bottom = 23mm
}
\setlength{\parskip}{0.65em}  % Sets paragraph skip
\setlength{\parindent}{0em}  % No paragraph indentation
\setlist[enumerate]{itemsep=0em,
    topsep=0.10em,
    leftmargin=*,
    label=\textbf{\alph*)}, wide}  % Sets default for enumerate
\frenchspacing  % Just ONE SPACE after the period, not two spaces

    % To get letters from numbers NOT needed 
%   \makeatletter
%   \newcommand{\makealph}[1]{\@alph{#1}}
%   \makeatother

% Environment for the rubric of a task.
\newcounter{outercounter}
\newcounter{innercounter}
\newenvironment{rubric}[1]{
    \stepcounter{outercounter}%
    \setcounter{innercounter}{1}% changed  alph counter <<<<<<<<<<<<<<<<<<<<<<
    \par%
    \begin{sffamily}%
        \textbf{Task \theoutercounter} (#1)\textbf{.}%
    }{
    \end{sffamily}%
    \par%
}
% Environment for a rubric item.  changed <<<<<<<<<<<<<<<<<<<<<<<<<<<<
\usepackage{environ} % added <<<<<<<<<<<<

\NewEnviron{rubricitem}{% changed <<<<<<<<<<
\sffamily\parbox{3.3ex}{\bfseries\alph{innercounter})}\BODY%
    \addtocounter{innercounter}{1}
}
%*********************************************************************

\begin{document}

    \begin{rubric}{With custom items}
        \lipsum[1][1]
    \end{rubric}

    \begin{rubricitem}
     \lipsum[1][2-5]
    \end{rubricitem}

        \lipsum[1][7-10]
        
    \begin{rubricitem}
        \lipsum[1][6-8]
    \end{rubricitem}

    \setcounter{innercounter}{9} % test a narrow label  <<<<<<<<<<<<
    \begin{rubricitem}
        \lipsum[1][6-8] 
    \end{rubricitem}

    \bigskip
    
    \begin{rubric}{With enumerate items}
        \lipsum[1][1]
        \begin{enumerate}
            \item \lipsum[1][2-5]
            \item \lipsum[1][6]
        \end{enumerate}
    \end{rubric}

\bigskip

\begin{rubric}{REPEAT With custom items}
    \lipsum[1][1]
\end{rubric}
\begin{rubricitem}
    \lipsum[1][2-5]
\end{rubricitem}

\lipsum[1][7-10]

\begin{rubricitem}
    \lipsum[1][6-8]
\end{rubricitem}

\setcounter{innercounter}{9} % test a narrow label  <<<<<<<<<<<<
\begin{rubricitem}
    \lipsum[1][6-8] 
\end{rubricitem}

\end{document}

答案2

我使用了 Simon Dispa 的回答中的想法来获得一个可能比我最初寻找的更好的结果,并且更接近我最初的尝试,因为它使用了\newenvironment

关键部分是使用\parbox

在此处输入图片描述

我还决定,将,所以我将 a\parbox与一个附加的组合在一起\hspace。这不是我在问题中要求的,但我认为它看起来更好,尤其是对于像或者

\documentclass[12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}  % Sets language
\usepackage{geometry}  % To establish the properties of the pages
\usepackage{enumitem}
\usepackage{lipsum}


%% General properties of the pages
\geometry{
 a4paper,
 left = 23mm,
 right = 23mm,
 top = 23mm,
 bottom = 23mm
}
\setlength{\parskip}{0.65em}  % Sets paragraph skip
\setlength{\parindent}{0em}  % No paragraph indentation
\setlist[enumerate]{itemsep=0em,
                    topsep=0.10em,
                    leftmargin=*,
                    label=\textbf{\alph*)},
                    wide}  % Sets default for enumerate
\frenchspacing  % Just ONE SPACE after the period, not two spaces

% To get letters from numbers
\makeatletter
\newcommand{\makealph}[1]{\@alph{#1}}
\makeatother

% Environment for the rubric of a task.
\newcounter{outercounter}
\newcounter{innercounter}
\newenvironment{rubric}[1]{
    \stepcounter{outercounter}%
    \setcounter{innercounter}{0}%
    \par%
    \begin{sffamily}%
    \textbf{Task \theoutercounter} (#1)\textbf{.}%
}{
    \end{sffamily}%
    \par%
}
% Environment for a rubric item.
\newenvironment{rubricitem}{
    \par%
    \begin{sffamily}%
    \stepcounter{innercounter}%
    \parbox{1em}{%
        \hfill\textbf{\makealph{\theinnercounter})}%
    }%
    \hspace{0.5em}\ignorespaces%
}{
    \end{sffamily}%
    \par%
}

\begin{document}
\begin{rubric}{With custom items}
\lipsum[1][1]
\end{rubric}
\begin{rubricitem}
\lipsum[1][2-5]
\end{rubricitem}
\lipsum[1][7-10]
\begin{rubricitem}
\lipsum[1][6]
\end{rubricitem}

\bigskip

\begin{rubric}{With enumerate items}
\lipsum[1][1]
\begin{enumerate}
    \item \lipsum[1][2-5]
    \item \lipsum[1][6]
\end{enumerate}
\end{rubric}
\end{document}

相关内容