\ Arraystretch ở đâu?

Sep 25 2020

setspace.stycho thấy doublespacingnhững thay đổi đó baselinestretch, nhưng mối quan hệ giữa baselinestretchvà ở arraystretchđâu? Tôi cần số lượng chính xác arraystretchđể thay đổi kích thước bmatrixs của mình. Căn chỉnh theo chiều dọc ma trận kết hợp với khoảng cách đôi hiển thị baselinestretch= 1/arraystretch, nhưng tôi có thể tìm thông tin này ở đâu? Có vẻ như không có setspace.styvà cũng không amsmath.stycó thông tin.

Trả lời

2 egreg Sep 25 2020 at 15:06

Khi một \setstretchlệnh hoặc lệnh dẫn xuất như \doublespacingđược đưa ra, giá trị bình thường của \baselineskipđược nhân với lệnh đã nêu \baselinestretch.

Khi arrayhoặc tabularđược bắt đầu, giá trị hiện tại của \baselineskipđược nhân với \arraystretch. Vì vậy, bạn muốn điều đó \arraystretchđược đặt thành nghịch đảo của \baselinestretch.

\documentclass[twocolumn]{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{xfp}

\newcommand{\fixstretch}{\edef\arraystretch{\fpeval{1/(\baselinestretch)}}}

\doublespacing

\begin{document}

Some text that should be long enough to be broken across lines
so as to show the interline spacing. But now we show a matrix
\[
\begin{bmatrix}
1 & 0 \\
0 & 1 \\
0 & 0
\end{bmatrix}
\]
The result is really awful. Now we try in a different way.

\fixstretch
Some text that should be long enough to be broken across lines
so as to show the interline spacing. But now we show a matrix
\[
\begin{bmatrix}
1 & 0 \\
0 & 1 \\
0 & 0
\end{bmatrix}
\]
Now the matrix is nice. Of course, the double spaced
text remains as ugly as it can be.

\end{document}

Bạn có thể tránh phải phát hành một cách rõ ràng \fixstretchbằng cách xác định lại \setstretch.

\documentclass[twocolumn]{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{xfp}

% fix \setstretch to also act on \arraystretch
\makeatletter
\renewcommand{\setstretch}[1]{%
  \def\baselinestretch{#1}%
  \edef\arraystretch{\fpeval{1/#1}}% <---- added code
  \@currsize
}
\makeatother

\doublespacing

\begin{document}

Some text that should be long enough to be broken across lines
so as to show the interline spacing. But now we show a matrix
\[
\begin{bmatrix}
1 & 0 \\
0 & 1 \\
0 & 0
\end{bmatrix}
\]
Now the matrix is nice. Of course, the double spaced
text remains as ugly as it can be.

\end{document}