这是抑制阵列上方和下方的垂直空间?,与(下面的黑色框)一起使用时效果很好\fbox
,但与(下面的青色框)一起使用时效果不佳\href
。我的目标是消除href
边界框似乎在array
环境周围放置的多余垂直空间:
如果href
边界框接近用途,\fbox
那就没问题了。
代码
\documentclass{article}
\usepackage{array}
\usepackage{environ}
\usepackage{booktabs}% for \addlinespace
\usepackage{hyperref}
\makeatletter
%% https://tex.stackexchange.com/questions/366123/suppress-vertical-space-above-and-below-array
\NewEnviron{mysolidarray}[1]{%
\begingroup
\def\arraystretch{0}%
\extrarowheight=\z@
\sbox\z@{$\begin{array}[t]{#1}\BODY\end{array}$}%
\sbox\tw@{$\begin{array}[b]{#1}\BODY\end{array}$}%
\expandafter\endgroup\expandafter
\firstlineheight\the\ht\expandafter\z@\expandafter
\lastlinedepth\the\dp\tw@\relax
\sbox{\solidarraybox}{$\begin{array}[t]{#1}\BODY\end{array}\m@th$}
\ht\solidarraybox=\firstlineheight
\dp\solidarraybox=\dimexpr\dp\solidarraybox-\dp\@arstrutbox+\lastlinedepth\relax
\box\solidarraybox
}
\makeatother
\newdimen\firstlineheight
\newdimen\lastlinedepth
\newsavebox{\solidarraybox}
\def\MyArrayContentA{\cdot \\[-2.0ex] \cdot}%
\def\MyArrayContentB{\cdot\cdot \\[-2.35ex] \cdot \\[-2.35ex] \cdot\cdot}%
\def\MyArrayA{%
\begin{array}[t]{@{}c@{}}
\MyArrayContentA
\end{array}%
}%
\def\MySolidArrayA{%
\begin{mysolidarray}{@{}c@{}}
\MyArrayContentA
\end{mysolidarray}%
}%
\def\MyArrayB{%
\begin{array}[t]{@{}c@{}}
\MyArrayContentB
\end{array}%
}%
\def\MySolidArrayB{%
\begin{mysolidarray}{@{}c@{}}
\MyArrayContentB
\end{mysolidarray}%
}%
\begin{document}
\fboxsep=0pt
\begin{tabular}{lll}
\verb|array|&
\fbox{$\MyArrayA$} \href{xxx}{$\MyArrayA$}
& \fbox{$\MyArrayB$} \href{xxx}{$\MyArrayB$}
\\\addlinespace[1.0ex]
\verb|mysolidarray|&
\fbox{$\MySolidArrayA$} \href{xxx}{$\MySolidArrayA$}
& \fbox{$\MySolidArrayB$} \href{xxx}{$\MySolidArrayB$}
\end{tabular}
\end{document}
答案1
\href
并没有真正添加额外的填充空间,只是通过黑魔法添加了视觉链接边框,并没有真正反映文本框尺寸。
如果您在\fbox
周围放置一个\href
,您会看到 tex 框仍然受到限制,事实上,似乎仅使用\mbox
就足以为 pdftex 提供所需链接边框尺寸的提示。
\documentclass{article}
\usepackage{array}
\usepackage{environ}
\usepackage{booktabs}% for \addlinespace
\usepackage{hyperref}
\makeatletter
%% https://tex.stackexchange.com/questions/366123/suppress-vertical-space-above-and-below-array
\NewEnviron{mysolidarray}[1]{%
\begingroup
\def\arraystretch{0}%
\extrarowheight=\z@
\sbox\z@{$\begin{array}[t]{#1}\BODY\end{array}$}%
\sbox\tw@{$\begin{array}[b]{#1}\BODY\end{array}$}%
\expandafter\endgroup\expandafter
\firstlineheight\the\ht\expandafter\z@\expandafter
\lastlinedepth\the\dp\tw@\relax
\sbox{\solidarraybox}{$\begin{array}[t]{#1}\BODY\end{array}\m@th$}
\ht\solidarraybox=\firstlineheight
\dp\solidarraybox=\dimexpr\dp\solidarraybox-\dp\@arstrutbox+\lastlinedepth\relax
\box\solidarraybox
}
\makeatother
\newdimen\firstlineheight
\newdimen\lastlinedepth
\newsavebox{\solidarraybox}
\def\MyArrayContentA{\cdot \\[-2.0ex] \cdot}%
\def\MyArrayContentB{\cdot\cdot \\[-2.35ex] \cdot \\[-2.35ex] \cdot\cdot}%
\def\MyArrayA{%
\begin{array}[t]{@{}c@{}}
\MyArrayContentA
\end{array}%
}%
\def\MySolidArrayA{%
\begin{mysolidarray}{@{}c@{}}
\MyArrayContentA
\end{mysolidarray}%
}%
\def\MyArrayB{%
\begin{array}[t]{@{}c@{}}
\MyArrayContentB
\end{array}%
}%
\def\MySolidArrayB{%
\begin{mysolidarray}{@{}c@{}}
\MyArrayContentB
\end{mysolidarray}%
}%
\begin{document}
\fboxsep=0pt
\begin{tabular}{lll}
\verb|array|&
\fbox{$\MyArrayA$} \href{xxx}{$\MyArrayA$}
& \fbox{$\MyArrayB$} \href{xxx}{$\MyArrayB$}
\\\addlinespace[1.0ex]
\verb|mysolidarray|&
\fbox{$\MySolidArrayA$} \href{xxx}{$\MySolidArrayA$} \mbox{\href{xxx}{$\MySolidArrayA$}}
& \fbox{$\MySolidArrayB$} \href{xxx}{$\MySolidArrayB$} \mbox{\href{xxx}{$\MySolidArrayB$}}
\end{tabular}
\end{document}