如何合并编号段落、两栏、悬挂缩进?

如何合并编号段落、两栏、悬挂缩进?

我无法将多个功能组合在一起。在下面的“numberedpars”之类的环境中,我想

  • ... 自动在双面书籍的左侧单独对段落进行编号,并为每个新环境重置计数器。数字应向右对齐。最好将数字作为文本的一部分,而不是在页边空白处。
  • ...将文本分为两列。
  • ... 段落的第一行没有缩进,并且后续行悬垂。

这可能吗?

我目前得到的结果:自动编号的段落(尽管它不完全在左侧,但数字不会向右对齐,并且数字在页边距中)。借用 TH 的回复:自动为每个段落分配一个编号

% !TeX TXS-program:compile = txs:///lualatex/[-synctex=1 -interaction=nonstopmode]

\documentclass[11pt]{scrbook}

\usepackage[ngerman]{babel}

\usepackage[excludeor]{everyhook}
\setlength{\marginparwidth}{8pt}
\newcounter{parcount}
\newif\ifnumberedpars
\newenvironment{numberedpars}{%
    \PushPreHook{par}{%
        \ifnumberedpars
        \stepcounter{parcount}%
        \numberedparsfalse
        \marginpar{\arabic{parcount}}%
        \numberedparstrue
        \fi
    }%
    \numberedparstrue
}{%
    \PopPreHook{par}%
}

\reversemarginpar

\begin{document}

\setlength{\parindent}{0pt}


\section*{Section Headline}

\subsection*{Subsection Headline}

Some info

\subsubsection*{Subsubsection Headline 1}

\begin{numberedpars}
AA: This is a short paragaph.

BB: This is a rather long paragraph spanning more than one line if we extend this really really long.

AA: Again another rather long long paragraph spanning more than one line if we extend this really really long.

BB: And here we stop this conversation.
\end{numberedpars}

\subsubsection*{Subsubsection Headline 2}

\setcounter{parcount}{0}
\begin{numberedpars}
    AA: This is a short paragaph.
    
    BB: This is a rather long paragraph spanning more than one line if we extend this really really long.
    
    AA: Again another rather long long paragraph spanning more than one line if we extend this really really long.
    
    BB: And here we stop this conversation.
\end{numberedpars}

\subsubsection*{Subsubsection Headline 3}

\setcounter{parcount}{0}
\begin{numberedpars}
    AA: This is a short paragaph.
    
    BB: This is a rather long paragraph spanning more than one line if we extend this really really long.
    
    AA: Again another rather long long paragraph spanning more than one line if we extend this really really long.
    
    BB: And here we stop this conversation.
\end{numberedpars}


\subsubsection*{Subsubsection Headline 4}

\setcounter{parcount}{0}
\begin{numberedpars}
    AA: This is a short paragaph.
    
    BB: This is a rather long paragraph spanning more than one line if we extend this really really long.
    
    AA: Again another rather long long paragraph spanning more than one line if we extend this really really long.
    
    BB: And here we stop this conversation.
\end{numberedpars}

\subsubsection*{Subsubsection Headline 5}

\setcounter{parcount}{0}
\begin{numberedpars}
    AA: This is a short paragaph.
    
    BB: This is a rather long paragraph spanning more than one line if we extend this really really long.
    
    AA: Again another rather long long paragraph spanning more than one line if we extend this really really long.
    
    BB: And here we stop this conversation.
\end{numberedpars}

\end{document}

我尝试添加更多上述功能,但都以失败告终。非常感谢大家提出任何可行的想法。

编辑:因为这很难解释,所以这里是我尝试做的一个用 LibreOffice Writer 创建的屏幕截图(尽管它仍然缺少被刷新的数字):

编辑2:啊,抱歉,第一个截图仍然缺少悬挂缩进,它应该是这样的(尽管并非所有内容都完全对齐):

在此处输入图片描述

编辑3:Celdor,您的 EDIT3 几乎做到了这一点。它仍然缺少一个真正的悬挂缩进。让我解释一下。如果我使用短首字母(如“II”)和长首字母(如“WvW”),间距就不再那么好了。要么“II”周围的空白太多,要么“WvW”周围的空白太少,因为首字母标签的大小是固定的。还可以看出首字母居中:

首字母周围的空格过多或不足

我认为真正的悬挂缩进需要首字母和文本连接起来。我设法做的是让首字母左对齐/对齐(对齐是我想要的),方法是将行中的更改c为并增加首字母后的空间(将 中的 1em 更改为 2em )。现在段落编号右对齐,首字母左对齐,并且有足够的空间容纳“II”和“WvW”:l\hspace{#3}\makebox[#4][l]{\textbf{#6:}}%\NewDocumentCommand{\numpar}{s O{0.5cm} O{2em} O{#2} O{#3} m}{%

段落编号右对齐,首字母左对齐,并留出足够的空间

现在对齐已经很好了,段落编号和首字母之间也留有空格。完美。- 但首字母和文本仍然不连贯。我要找的是:

首字母和正文是相连的,但始终使用一定大小的悬挂缩进。

首字母和文本是相连的,但始终使用具有一定大小的悬挂缩进。总结一下:我不希望首字母周围的空间是固定的,而是希望首字母和文本是相连的,并且悬挂缩进的大小是固定的。我希望这能澄清我遗漏的内容。

答案1

如果我的描述正确的话,我建议混合使用 hangindent、hspace 和 makebox

编辑。多列示例。解决方案基于tabular

EDIT2。
添加了一个由 执行的单列选项*;这可以在页面之间中断。两列解决方案可以根据要求从一列流到另一列,但不能在页面之间传播。似乎我想到的每个解决方案都需要使用框。也许它需要一些我仍在学习的内部编码,因此恐怕没有关于该特定功能的解决方案。

   
AAA AAA
\documentclass{article}
\usepackage{array}
\usepackage{kantlipsum}
\usepackage{multicol}
\usepackage{microtype}
\usepackage{geometry}

\newcounter{parcounter}
\newlength\hanglength

\NewDocumentCommand{\mypar}{s O{0pt} O{1cm} O{6pt} O{#3} O{#4} m m}{%
    % #1 - * for a single column
    % #2 - indentation before a number
    % #3 - width of a box containing a paragraph number
    % #4 - separation length after the number
    % #5 - width of a box containing a label
    % #6 - separation length after the label
    % #7 - label
    % #8 - the paragraph
    \setlength{\hanglength}{\dimexpr(#2 + #3 + #4 + #5 + #6)}
    \stepcounter{parcounter}
    \noindent
    \IfBooleanTF{#1}%
    {%
        \hspace{#2}\makebox[#3][r]{\arabic{parcounter}}%
        \hspace{#4}\makebox[#5][c]{#7}%
        \hspace{#6}%
        \hangindent=\hanglength\relax%
        #8\par
    }{%
        \begin{tabular*}{\textwidth}{
                @{\hspace{#2}}
                >{\raggedleft\arraybackslash}p{#3}
                @{\hspace{#4}}
                >{\centering\arraybackslash}p{#5}
                @{\hspace{#6}}
                p{\dimexpr(\textwidth-\hanglength)}
                @{}
            }
            \arabic{parcounter} &
            #7 &
            \begin{minipage}[t]{\linewidth}
                \null\vspace{-\baselineskip}\begin{multicols}{2}#8\end{multicols}
            \end{minipage}
        \end{tabular*}\vspace{0.5\baselineskip}\par}}
\NewDocumentEnvironment{numberedpars}{+b}{%
    \setcounter{parcounter}{0}
    \setlength{\tabcolsep}{0pt}\par#1}{}


\begin{document}
\parindent=0pt

\section*{Section Headline}

\subsection*{Subsection Headline}

Some info

\begin{numberedpars}
    \mypar{AA}{\kant*[1][1-2]}
    \mypar{BB}{\kant*[2][1]}
    \mypar{AA}{\kant*[3][1]}
    \mypar{BB}{\kant*[4][1]}
    \mypar{AA}{\kant*[5][1]}
    \mypar{BB}{\kant*[6][1]}
    \mypar{CC}{\kant*[7][1]}
    \mypar{AA}{\kant*[8][1-3]}
    \mypar{BB}{\kant*[1][1-3]}
    \mypar{AA}{\kant*[2][1]}
    \mypar{BB}{\kant*[3][1]}
\end{numberedpars}

\subsection*{Subsection Headline}

\kant[2][1]

\begin{numberedpars}
    \mypar*{CC}{\kant*[1][1-3]}
    \mypar*{DD}{\kant*[2][1-3]}
    \mypar{CC}{\kant*[3][1-3]}
    \mypar{DD}{\kant*[4][1-3]}
    \mypar*{CC}{\kant*[5][1-2]}
    \mypar*{DD}{\kant*[6][1-2]}
\end{numberedpars}

\end{document}

编辑3

具有双列部分的解决方案。

   
AAA AAA
\documentclass{article}
\usepackage{multicol}
\usepackage{microtype}
\usepackage{geometry}
\usepackage{kantlipsum}

\newcounter{parcounter}

\NewDocumentCommand{\numpar}{s O{0.5cm} O{1em} O{#2} O{#3} m}{%
    % #1 - star - suppresses annotations
    % #2 - width of a box containing a paragraph number
    % #3 - separation length after the number
    % #4 - width of a box containing a label
    % #5 - separation length after the label
    % #6 - label
    %
    % \dimen0 contains width of a numbers and labels
    \setlength{\dimen0}{\dimexpr(#2 + #3 + #4 + #5)}
    \noindent
    \IfBooleanTF{#1}{\hspace{\dimen0}}{%
        \stepcounter{parcounter}%
        \makebox[#2][r]{\arabic{parcounter}}%
        \hspace{#3}\makebox[#4][c]{\textbf{#6:}}%
        \hspace{#5}}%
    \hangindent=\dimen0}

\NewDocumentEnvironment{numberedpars}{O{0.25pt} +b}{%
    \setcounter{parcounter}{0}
    \setlength{\columnseprule}{#1}
    \begin{multicols}{2}
        #2%
    \end{multicols}}{}

\begin{document}
\parindent=0pt

\section*{Section Headline}

\subsection*{Subsection Headline}

Some info

\begin{numberedpars}
    \numpar{AA} \kant*[1][1-2]
    
    \numpar{BB} \kant*[2][1-2]
    
    \numpar{AA} \kant*[3][1-2]
    
    \numpar{BB} \kant*[4][1-2]
    
    \numpar{AA} \kant*[5][1-2]
    
    \numpar{BB} \kant*[6][1-2]
    
    \numpar{AA} \kant*[7][1-2]
    
    \numpar{BB} \kant*[8][1-2]
    
    \numpar*{AA} \kant*[9][1-2]
    
    \numpar*{BB} \kant*[10][1-2]
    
    \numpar{BB} \kant*[3][1-3]
\end{numberedpars}

\section*{Another Section Headline}

\subsection*{Another Subsection Headline}

Even more info

\begin{numberedpars}[2pt]
    \numpar{CC}\kant*[1][1-3]
    
    \numpar*{}\kant*[2][1]
    
    \numpar{DD} \kant*[2][1-3]
    
    \numpar{CC} \kant*[3][1-3]
    
    \numpar{DD} \kant*[4][1-3]
    
    \numpar{CC} \kant*[5][1-2]
    
    \numpar{DD} \kant*[6][1-2]
\end{numberedpars}

\end{document}


EDIT4
首字母不再列在表格中。

   
第 1 页,共 4 页 第 2 页,共 4 页
\documentclass{article}
\usepackage{etoolbox}
\usepackage{multicol}
\usepackage{microtype}
\usepackage{geometry}
\usepackage{kantlipsum}

\makeatletter
    \newcounter{p@rc@unter}
    \NewDocumentCommand{\numpar}{s O{0.5cm} O{6pt} O{1cm} m}{%
        % #2 - width of a box containing a paragraph number
        % #3 - space between the number and initials
        % #4 - space of a hanging indentation
        % #5 - initials
        \hangindent=#4
        \IfBooleanTF{#1}{\hspace{#4}}{
            \stepcounter{p@rc@unter}
            \settowidth{\dimen0}{\arabic{p@rc@unter}}
            \setlength{\dimen1}{#2}
            \ifdim\dimen0<\dimen1
                \setlength{\dimen0}{\dimen1}
            \fi
            \makebox[\dimen0][r]{\arabic{p@rc@unter}}\hspace{#3}%
            \notblank{#5}{\textbf{#5:}}{}}}
    \NewDocumentEnvironment{numberedpars}{s O{0.4pt} O{14pt} +b}{%
        % #1 - * - if present, keep counting paragraphs without cancelling
        % #2 - column rule width
        % #3 - space between columns
        \IfBooleanF{#1}{\setcounter{p@rc@unter}{0}}
        \setlength{\parindent}{0pt}
        \setlength{\columnseprule}{#2}
        \setlength{\columnsep}{#3}
        \begin{multicols}{2}
            #4\par
        \end{multicols}}{}
\makeatother


\begin{document}
% \setlength{\parindent}{0pt}

\section*{Section Headline}
\subsection*{Subsection Headline}
Some info

\begin{numberedpars}
    \numpar{AA}
    \kant[1][1]

    \numpar{BB}
    \kant*[2][1-3]

    \numpar{II} \kant*[4][1-2]

    \numpar{WwW} \kant*[5][1]

    \numpar{D} \kant*[6][1]

    \numpar{EEE} \kant*[7][1-2]

    \numpar{II} \kant*[4][1-2]

    \numpar{WwW} \kant*[5][1]

    \numpar{D} \kant*[6][1]

    \numpar{EEE} \kant*[7][1-2]
\end{numberedpars}

\kant[10][1-3]


\section*{Section Headline}
\subsection*{Subsection Headline}
Some other info

\begin{numberedpars}
    \numpar{CDT}
    \kant*[8][1-2]

    \numpar{JPJ}
    \kant*[9][1-2]
\end{numberedpars}

Something

\begin{numberedpars}*
    \numpar{XYZABCD} \kant*[10][1-2]

    \numpar{II} \kant*[11][1-2]

    \numpar{WvW} \kant*[12][1-2]

    \numpar{D} \kant*[13][1-2]
\end{numberedpars}
\end{document}

相关内容