阵列中的行之间有更多垂直空间

阵列中的行之间有更多垂直空间

为了更清晰,我希望数组的行之间留出更多空间。我尝试在行末尾使用 \vspace{},但 LateX 忽略了它。我可以通过添加额外的行来实现接近我想要的效果,但这会增加比我想要的更多的空间(但我可以忍受)。这是我所拥有的:

\documentclass{amsbook} 
\begin{document}
BEFORE:

\[
f(n) = \left\{ 
\begin{array}{cl} 
        0 & \text{if n=1 }\\ 
        \frac{n}{2} & \text{if n is even} \\ 
        -\left( \frac{n-1}{2}  \right)   & \text{if n $\ge$ 1 is odd} 
\end{array} \right.
\]

This is cramped visually, especially given my poor eyesight.

AFTER:

\[
f(n) = \left\{ 
\begin{array}{cl} 
        0 & \text{if n=1 }\\ 
        \\
        \frac{n}{2} & \text{if n is even} \\ 
        \\
        -\left( \frac{n-1}{2}  \right)   & \text{if n $\ge$ 1 is odd} 
\end{array} \right.
\]

This works but is overkill.
\end{document}

答案1

\\命令有一个可选的长度参数。因此您可以添加,例如,

\documentclass{amsbook} 
\begin{document}
BEFORE:

\[
f(n) = \left\{ 
\begin{array}{cl} 
        0 & \text{if n=1 }\\[6pt] 
        \frac{n}{2} & \text{if n is even} \\[9pt] 
        -\left( \frac{n-1}{2}  \right)   & \text{if n $\ge$ 1 is odd} 
\end{array} \right.
\]

This is cramped visually, especially given my poor eyesight.

AFTER:

\[
f(n) = \left\{ 
\begin{array}{cl} 
        0 & \text{if n=1 }\\[12pt] 
        \frac{n}{2} & \text{if n is even} \\[15pt] 
        -\left( \frac{n-1}{2}  \right)   & \text{if n $\ge$ 1 is odd} 
\end{array} \right.
\]

This works but is overkill.
\end{document}

根据您的口味。

说实话,我宁愿写 -\left( \dfrac{n-1}{2} \right) & \text{if $n \ge 1$ is odd}等等,这样数字 $n$ 就始终处于数学模式。

答案2

您可以尝试+array提供的环境tabularray包裹:

\documentclass{amsbook} 

\usepackage{tabularray}
\UseTblrLibrary{amsmath}

\begin{document}

This \verb!+array! environment sets default vertical space \verb!rowsep=2pt!:

\[
f(n) = \left\{ 
\begin{+array}{@{}cl} 
        0 & \text{if n=1 }\\ 
        \frac{n}{2} & \text{if n is even} \\ 
        -\left( \frac{n-1}{2}  \right)   & \text{if n $\ge$ 1 is odd} 
\end{+array} \right.
\]

You may also adjust the vertical space by changing \verb!rowsep!:

\[
f(n) = \left\{ 
\begin{+array}{colspec={@{}cl},rowsep=1pt} 
        0 & \text{if n=1 }\\ 
        \frac{n}{2} & \text{if n is even} \\ 
        -\left( \frac{n-1}{2}  \right)   & \text{if n $\ge$ 1 is odd} 
\end{+array} \right.
\]

\end{document}

在此处输入图片描述

答案3

@LRJ 答案中第一个例子的变体(+1):

\documentclass{amsbook}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}

\begin{document}
\[
f(n) = \left\{
\begin{+array}{colspec={@{}c Q[l, mode=text]} }
                    0   &   if $n=1$            \\
         \frac{n}{2}    &   if $n$ is even      \\
        -\frac{n-1}{2}  &   if $n \ge 1$ is odd
\end{+array} \right.
\]
\end{document}

在此处输入图片描述

相关内容