有人能向我解释一下这里幕后发生了什么吗?我以为乳胶会忽略空行...
我定义了以下命令
\newcommand{\requirement}[3]{
\textcolor{blue}{#1 \hfill SysReq-{#2}}\\
\textcolor{blue}{\rule{\textwidth}{1.0pt}}
{#3}
\vspace{\belowdisplayskip}
}
如果我像这样使用它
\requirement{Test 3}{3}{
This is some requirement text defined with the command. Let's make it a bit longer so it spans more than one line of text.
}
\requirement{Test 4}{4}{
This is some other requirement text defined with the command.
}
但是如果我在两者之间添加一条注释行(而不是一行空白),它们就会挤在一起。
两个命令之间的空行起什么作用?
答案1
\vspace
是两个 TeX 基元的 LaTeX 包装器\vskip
,并且\vadjust
:\vskip
插入垂直粘合,并在水平模式下遇到时启动垂直模式,而\vadjust
在水平模式下插入垂直材料。
在您当前的定义中,\vspace
在水平模式下遇到(除非您在宏的第三个参数中手动开始一个新段落),因此\vadjust
执行分支。因此,在两次连续调用之间不留空行\requirement
会导致您观察到的结果。
为了解决这个问题,只需在\par
之前引入一个\vspace
。我引入了另外几个改进(?)。
\documentclass{article}
\usepackage{xcolor}
\makeatletter
\newcommand{\requirement}[3]{%
\par\noindent
\begin{minipage}{\linewidth}
\color{blue}%
\leavevmode\ignorespaces#1 \hfill SysReq-\ignorespaces#2\\
\rule[1ex]{\textwidth}{1.0pt}%
\end{minipage}%
\par\nobreak\@afterheading
\noindent\ignorespaces#3
\par\vspace{\belowdisplayskip}
}
\makeatother
\begin{document}
\requirement{Test 1}{1}{% <-- Not necessary since I've used \ignorespaces
This is some requirement text defined with the command.
Let's make it a bit longer so it spans more than one line of text.
}
\requirement{Test 2}{2}{%
This is some requirement text defined with the command.
Let's make it a bit longer so it spans more than one line of text.
}
\requirement{Test 3}{3}{%
This is some requirement text defined with the command.
Let's make it a bit longer so it spans more than one line of text.
}
\end{document}