NiceTabular (NiceMatrix) 沒有垂直規則的空白行

NiceTabular (NiceMatrix) 沒有垂直規則的空白行

我正在嘗試在NiceTabular環境中添加一個小的空白行。這NiceMatrix 手動的規定(第 5.1.1 節垂直規則):

在nicematrix環境下,|指定的垂直規則在環境的前導碼中永遠不會被破壞,即使是由不完整的行或由 \hline\hline 指定的雙水平規則

這意味著這裡的空白行顯示垂直規則:

\begin{table}[h]
    \small
    \centering
    \begin{NiceTabularX}{\textwidth}{ll}[hvlines]
        \textit{Year}
        &
        \textit{Fruit}
    \\ \hline \hline
        2022
        &
        Apple
    \\
    \end{NiceTabularX}
\end{table}

在此輸入影像描述

對塊的快速嘗試給出了一條完整高度的線,該線仍然包括最外面(=邊界)垂直規則。

\begin{table}[h]
    \small
    \centering
    \begin{NiceTabularX}{\textwidth}{ll}[hvlines]
        \textit{Year}
        &
        \textit{Fruit}
    \\ \Block{1-2}{\hline \hline} \\
        2022
        &
        Apple
    \\
    \end{NiceTabularX}
\end{table}

在此輸入影像描述

如何在沒有任何垂直規則的情況下在行之間獲得一個小空行?

答案1

您可以使用經典的規則(由 載入的{tabular}套件的規則)。arraynicematrix

這意味著:

  • 您使用經典命令\hline(以及\hline\hline雙重規則);
  • 您必須使用經典的行為定義列類型|array該經典|array已被覆蓋nicematrix):\newcolumntype{I}{!{\vrule}}將完成這項工作。
\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\newcolumntype{I}{!{\vrule}}

\begin{table}[h]
\small
\centering
\begin{NiceTabular}{IlIlI}
    \hline
    \textit{Year}
    &
    \textit{Fruit} \\
    \hline\hline
    2022
    &
    Apple \\
    \hline
\end{NiceTabular}
\end{table}

\end{document}

當然,在該範例中,使用{NiceTabular}(我會使用{tabular})是沒有意義的,但您可能想要使用nicematrix真實表格中提供的其他功能)。

上述程式碼的輸出


另一方面,請記住 的主要特徵nicematrix是在經典 .txt 檔案的儲存格、列和行下插入 PGF/Tikz 節點{tabular}。這意味著始終可以透過使用這些節點在 Tikz 中繪製任何您想要的規則。


\begin{table}[h]
\small
\centering
\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular}{ll}[hvlines]
    \textit{Year}
    &
    \textit{Fruit} \\
    2022
    &
    Apple \\
\CodeAfter
    \tikz \draw [line width = 2 \pgflinewidth] (2-|1) -- (2-|last) ; 
    \tikz \draw [white, shorten > = -1 pt, shorten <= -1 pt] (2-|1) -- (2-|last) ; 
\end{NiceTabular}
\end{table}

\end{document}

第二段程式碼的輸出

相關內容