Combine numbered paragraphs, two columns, hanging indentation

columnshangindentnumberingparagraphstwo-column

I have trouble combining several features. In an environment like "numberedpars" below, I would like to

  • … automatically number paragraphs exclusively on the left side in a two-sided book and reset the counter for each new environment. The numbers should be flushed right. Preferably, the numbers should be part of the text and not in the margin.
  • … have the text in two columns.
  • … have the first line of a paragraph not indented and the following lines hanging.

Is this even possible?

What I got so far: Automatically numbered paragraphs (even though it's not exclusively on the left side, the numbers are not flushed right, and the numbers are in the margin). Borrowed from the reply by T.H. here: Automatically assign a number to every paragraph

% !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}

All my attempts to add more of the mentioned features has broken things for me. I greatly appreciate any working ideas.

Edit: Because it is rather difficult to explain, here is a screenshot of what I'm trying to do, created with LibreOffice Writer (though it's still missing the numbers being flushed right):

Edit 2: Ah sorry, the first screenshot was still missing the hanging indentation, it should look like this (even though not everything is perfectly aligned yet):

enter image description here

Edit 3: Celdor, your EDIT3 almost does it. It is still missing a genuine hanging indent. Let me explain. In case I use short initials (like "II") and long initials (like "WvW") spacing is not so nice anymore. There is either too much white space around "II" or not enough around "WvW" because the size of the initials label is fixed. It also becomes apparent that the initials are centered:

Too much or not enough whitespace around the initials

I think a genuine hanging indent needs the initials and the text to be connected. What I manage to do is have the initials flush left/justify (justification is what I'm looking for) by changing c to l in the line \hspace{#3}\makebox[#4][l]{\textbf{#6:}}% and raise the space after the initials (changing 1em to 2em in \NewDocumentCommand{\numpar}{s O{0.5cm} O{2em} O{#2} O{#3} m}{%). Now the paragraph numbers are flush right, and the initials are flush left and there is enough space for both "II" and "WvW":

Paragraph numbers flush right, initials flush left and enough space

Now justification is all good and there is some space between paragraph numbers and initials. Perfect. – But initials and text are still disconnected. What I'm looking for is this:

Initials and text are connected, still a hanging indent with a certain size is used throughout.

Initials and text are connected, still a hanging indent with a certain size is used throughout. To summarize: I don't want the space around the initials to be fixed, but initials and text to be connected and the size of the hanging indent to be fixed. I hope this clarifies what I'm missing.

Best Answer

If I have got the description right, I'd propose using a mix of hangindent, hspace, and makebox

EDIT. Example with multi-columns. The solution is based on tabular.

EDIT2.
Added an option for a single column, which is executed by *; this can be broken between pages. The two columns solution has a flow from one column to the other as requested but can't be spread between pages. It seems each solution I came up with required usage of boxes. Perhaps it would require some internal coding which I am still learning, hence no solution on that particular feature, I am afraid.

   
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}

EDIT3

A solution with the two-column sections.

   
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
Initials are no longer tabulated.

   
Page 1 of EDIT 4 Page 2 of EDIT 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}
Related Question