我们发出了一个命令来打印我们的软件需求,但是现在我们遇到了占用大量空间的东西,我们遇到了溢出问题。
我们使用table
环境来将所有内容放在一起,避免出现奇怪的事情,例如最后一个栏出现在不同的页面上,但这显然是一种黑客行为。我使用两个tabular
s,因为在一个巨大的表格单元格中写文字令人沮丧,因为白线不再导致段落中断。
我该如何改变这种情况,以便溢出消失,并且如果需求分布在 2 页上,每个部分至少有几行内容?最好不要对已经使用的情况进行太多编辑?
\documentclass[12pt,a4paper]{report}
\usepackage{booktabs}
\newcommand{\requirement}[5]{
\begin{table}[H]
\begin{tabular*} {\textwidth} { p{0.70\textwidth} r }
\toprule
\emph{#3} & \textbf{ID.#1.#2} \\
\midrule
\end{tabular*}
#4
\vspace{10pt}
\textbf{Motivation:}\\
#5
\vspace{-5pt}
\begin{tabular*}{\textwidth}{@{}p{\textwidth}}
\bottomrule
\end{tabular*}
\end{table}
}
\begin{document}
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long
long\\long\\long\\long\\long\\long\\
\requirement{R}{6}{Name}
{Requirement way to long
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long
}
{motivation}
\end{document}
答案1
\documentclass[12pt,a4paper]{report}
\newcommand{\requirement}[5]{\par
\smallskip
\hrule
\nopagebreak
\noindent{\large\strut}\textit{#3}\hfill\textbf{ID.#1.#2}
\par
\nopagebreak
\hrule
\par
\nopagebreak
\smallskip
\clubpenalty10000
#4 \par
\par
\nopagebreak
\hrule
\noindent{\large\strut}\textbf{Motivation:}\par
\smallskip
\clubpenalty10000
#5\par
\par
\nopagebreak
\hrule
\par
}
\begin{document}
\requirement{R}{6}{Name}
{Requirement way to long
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long
}
{motivation}
\end{document}
答案2
用一个longtable
。
梅威瑟:
\documentclass[12pt,a4paper]{report}
\usepackage{booktabs,longtable,array}
\newcommand{\requirement}[5]{%
\begin{longtable}[l]{@{}p{0.70\textwidth}>{\raggedleft\arraybackslash}p{\dimexpr0.30\textwidth-4\tabcolsep}}
\toprule
\emph{#3} & \textbf{ID.#1.#2} \\
\midrule
#4
\end{longtable}
\vspace{10pt}
\noindent\textbf{Motivation:}\par
\noindent#5
\vspace{-5pt}
\noindent\rule{\linewidth}{1pt}%
}
\begin{document}
\requirement{R}{6}{Name}
{Requirement way to long
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\
long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\long\\
}
{motivation}
\end{document}
输出