我想设置一个由文章、边注和大多数情况下的段落(\abs
)组成的法律文本。边注应始终与文章文本的第一行位于同一行,无论是否为段落。
\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}
我尝试使用边注,但那里的注释只是重叠。然后我尝试测量边注的高度,并将文章主体放在一个具有该尺寸的框中,但失败了。我在这个网站和网络上找到的测量方法对于像我这样的初学者来说很难理解。
但也许这不是解决问题的办法。我也考虑过使用表格,但文档会双面和marginpars 应该始终位于页面的外部。也许有一种方法可以根据表格是在奇数页还是偶数页来切换表格的行,但我也找不到解决方案。
当然,我可以在文章之间使用 vspace,但由于它将是一个非常大的文档,所以我希望自动调整空间。
答案1
经过多次测试,我找到了一个可以满足我要求的解决方案。它可能不太优雅,但确实有效。
\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}
答案2
以上是您的原始内容。“=====”下方是建议的修复,通过重新定义 实现\art
。[已编辑以修复左边距和 marginpar 中的 raggedright]。还请注意,通过使用\tabular
建议的修复,文章不会在页面边界中途中断。
\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}