2

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.

  • Welcome to TeX-SX! You may have a look at our starter page for a quick intro if you wish to familiarize yourself with our format. – Claudio Fiandrino May 1 '13 at 9:18
2

After a lot of testing I found a solution that does what I want. It may not be very elegant, but it does the trick.

\documentclass[parskip=half-]{scrbook}
\usepackage{calc}

\newlength\marginalie
\newlength\article
\newlength\difference

\newcommand{\art}[3]{
    \settototalheight\marginalie{\parbox{\marginparwidth}{\footnotesize #2}}
    \settototalheight\article{\parbox{\textwidth}{#3}}
    \setlength{\difference}{\the\marginalie-\the\article}
    \textbf{Art.\,#1}\\*[0.5ex]\clubpenalty=10000\marginpar{\flushleft\footnotesize #2}#3\par
    \ifnum\difference>0 \vspace{\the\difference} \else \addvspace{1ex} \fi
}
\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}
1

The above is your original. Below the "=====" is the proposed fix, achieved by redefining \art. [EDITED to fix left margin and raggedright in marginpar]. Note also that, by using \tabular as the proposed fix, that an article will not break midway across a page boundary.

\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.}
}

==========================================

\renewcommand\art[3]{%
\textbf{Art.\,#1\rule[-1ex]{0ex}{1ex}}\\
\begin{tabular}{@{\hspace{0ex}}ll}
\parbox[t]{\textwidth}{#3} & \parbox[t]{1in}{\raggedright\footnotesize#2}\\
\end{tabular}
}

\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}

enter image description here

  • 1
    Some articles are very long. That they don't break midway unfortunately prevents your fix from solving my problem. Furthermore, it's going to be a twosided document and I'd like the marginpars – if possible – to be on the outside of a page. But with your fix they are always on the right side. – Fabian May 1 '13 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.