I'd like to set a law text consisting of articles, marginal notes and, in most cases, paragraphs (\abs). The marginal notes should always start on the same line as the first line of the article text, be it a paragraph or not.
\documentclass[parskip=half-]{scrbook}
\newcommand\mpar[1]{\marginpar{\flushleft\footnotesize #1}}
\newcommand{\art}[3]{\textbf{Art.\,#1}\\*[0.5ex]\mpar{#2}#3\par}
\newcommand{\abs}[2]{\textsuperscript{#1~}#2\\}
\newcommand{\absl}[2]{\textsuperscript{#1~}#2} % for last paragraphs
\begin{document}
\art{1}{marginpar for article~1}{%
\abs{1}{The first line of the article text should be on the same line as the corresponding marginpar.}
\absl{2}{So this article is how it should be.}
}
\art{2}{Very\\long\\marginpar\\for article~2}{%
This article is okay, too. But if the marginpar uses more vertical space than this text...}
\art{3}{incorrect marginpar}{%
\abs{1}{...then this article text is not on the same line with its corresponding marginpar anymore.}
\absl{2}{Another paragraph.}
}
\end{document}
I tried to use marginnote but there the notes just overlap. Then I tried to measure the height of the marginal note and set the article body in a box with that size but failed miserably. The measuring methods I found on this website and on the web in general are very hard to understand for a beginner like me.
But maybe that's not even the way to go. I also thought about using a tabular, but the document will be twosided and the marginpars should always be on the outside of the page. Maybe there is a way to switch the rows of a tabular depending on if it's on an odd or even page but I couldn't find a solution for this either.
Of course I could use a vspace between the articles but since it's going to be a very big document, I'd like to have the space adjusted automatically.
