我仍在努力array
在环境中设置精确的空间我觉得我已经接近预期目标了。我发现我可以重新定义,\@arraycr
这样它就不会包含\arraystretch
乘数了。
以下是我目前所掌握的信息
\documentclass{article}
%\usepackage{amsmath} %solution should be compatible with these packages
%\usepackage{array}
\begin{document}
\makeatletter
\def\arraystretch{0}
\def\@arraycr{\cr\rule{1pt}{1cm}}
\makeatother
\[
\begin{array}{ccc}
a=b & 111111 & d \\
2\dfrac222 & 3 & 444
\end{array}
\]
\end{document}
\rule
为了使其可视化,我特意设置了的宽度(稍后我将把它设置为0pt
)。
如您所见,的锚点\rule
是基线,即规则从基线开始增长,但我希望它从整条线的最顶端开始增长,就像这样
因此1cm
在这种情况下行与行之间的实际间距就是指定的。
我怎样才能做到这一点?
答案1
下面的代码为环境\\
中使用的添加了一个默认可选值array
,因此\\
与相同\\[\arrayrowsep]
,其中\arrayrowsep
是新提供的长度。
\documentclass{article}
\usepackage{amsmath} %solution should be compatible with these packages
\usepackage{array}
\renewcommand*\arraystretch{0}
\newlength{\arrayrowsep}
\setlength{\arrayrowsep}{1cm}
\makeatletter
\def\@xarraycr{\@ifnextchar[\@argarraycr{\@argarraycr[\arrayrowsep]}}
\makeatother
% visualize row sep
\newcommand\myrule{\rlap{\smash{\rule[-1cm]{1pt}{1cm}}}}
\begin{document}
\[
\begin{array}[t]{ccc}
a\myrule =b & 111111 & d \\
2\dfrac222 & 3 & 444
\end{array}
\]
\end{document}
更新:响应 OP 的后续请求,现在
\\
== 旧\\[\arrayrowsep]
\\[<sep>]
== 旧\\[\dimexpr\arrayrowsep+<sep>]
\\
请注意,这会改变环境中的更多默认行为和实现array
。使用时请自负风险。
\documentclass{article}
\usepackage{amsmath} %solution should be compatible with these packages
\usepackage{array}
\usepackage{color} % for visualizing row sep only
\renewcommand*\arraystretch{0}
\newlength{\arrayrowsep}
\setlength{\arrayrowsep}{1cm}
\makeatletter
% before, in latex kernel or array.sty
% \def\@xarraycr{\@ifnextchar[\@argarraycr {\ifnum 0=`{}\fi\cr}}
\def\@xarraycr{%
\@ifnextchar[\@argarraycr{\@argarraycr[0pt]}}
% before, in array.sty
% \def\@argarraycr[#1]{\ifnum0=`{}\fi\ifdim #1>\z@
% \expandafter\@xargarraycr\else
% \expandafter\@yargarraycr\fi{#1}}
\def\@argarraycr[#1]{%
\expandafter\@argarraycr@i\expandafter{\the\dimexpr\arrayrowsep+#1}}
\def\@argarraycr@i#1{\ifnum0=`{}\fi\ifdim #1>\z@
\expandafter\@xargarraycr\else
\expandafter\@yargarraycr\fi{#1}}
% visualize row sep
\newlength{\myrule@ht}
\newcommand\myrule[1]{%
\setlength{\myrule@ht}{\dimexpr#1\relax}%
\rlap{\smash{\rule[-\arrayrowsep]{1pt}{\arrayrowsep}}}%
\ifdim\myrule@ht=\arrayrowsep
\else
\ifdim\myrule@ht>\arrayrowsep
\rlap{\smash{\textcolor{blue}{%
\rule[-\dimexpr\myrule@ht]{2pt}{\dimexpr\myrule@ht-\arrayrowsep}}}}%
\else
\rlap{\smash{\textcolor{red}{%
\rule[-\dimexpr\arrayrowsep]{2pt}
{\dimexpr\arrayrowsep-\myrule@ht}}}}%
\fi
\fi
}
\makeatother
\begin{document}
\[
\begin{array}[t]{ccc}
a\myrule{1cm} =b & 111111 & d \\
2\dfrac222 & 3 & 444
\end{array}
\qquad
\begin{array}[t]{ccc}
a\myrule{1cm+1ex} =b & 111111 & d \\[1ex]
2\dfrac222 & 3 & 444
\end{array}
\qquad
\begin{array}[t]{ccc}
a\myrule{1cm-1ex} =b & 111111 & d \\[-1ex]
2\dfrac222 & 3 & 444
\end{array}
\]
\end{document}