两个 NiceTabular 未垂直对齐

两个 NiceTabular 未垂直对齐
\documentclass{article}
\usepackage{tikz}
\usepackage{nicematrix}

\begin{document}
Some text

\begin{center}
  \begin{NiceTabular}[width=10cm]{X[1,l]}[hlines,vlines]
    \RowStyle[cell-space-top-limit=5pt, cell-space-bottom-limit=10pt]{}
    Some text \\
    \RowStyle[cell-space-top-limit=10pt, cell-space-bottom-limit=5pt]{}
    Some text
  \end{NiceTabular}
\end{center}

Some text

\begin{center}
  \begin{NiceTabular}[width=10cm]{X[1,l]}[hlines,vlines]
      \RowStyle[cell-space-top-limit=5pt, cell-space-bottom-limit=10pt]{}
      Some text \\
      \RowStyle[cell-space-top-limit=10pt, cell-space-bottom-limit=5pt]{}
      Some text
      \CodeAfter
      \tikz \draw (1-|1) -- (2-|2);
      \tikz \draw (2-|1) -- (3-|2);
    \end{NiceTabular}
\end{center}

\end{document}

这两个表没有完全对齐。我该如何修复它?当我删除 tikz 指令时,它们就对齐了。

答案1

水平移动是由于两行之间的换行符引起的\tikz \draw ...;,TeX 将其转换为空格。

无论是使用单个换行符\tikz { \draw ...; \draw ...;}还是注释掉该换行符都可以。

\documentclass{article}
\usepackage{tikz}
\usepackage{nicematrix}

\begin{document}
Some text

\begin{center}
  \begin{NiceTabular}[width=10cm]{X[1,l]}[hlines,vlines]
    \RowStyle[cell-space-top-limit=5pt, cell-space-bottom-limit=10pt]{}
    \leavevmode\rlap{\color{blue}\smash{\rule[-.9\textheight]{.4pt}{\textheight}}}Some text \\
    \RowStyle[cell-space-top-limit=10pt, cell-space-bottom-limit=5pt]{}
    Some text
  \end{NiceTabular}
\end{center}

Solution 1, single \verb|\tikz|

\begin{center}
  \begin{NiceTabular}[width=10cm]{X[1,l]}[hlines,vlines]
      \RowStyle[cell-space-top-limit=5pt, cell-space-bottom-limit=10pt]{}
      Some text \\
      \RowStyle[cell-space-top-limit=10pt, cell-space-bottom-limit=5pt]{}
      Some text
      \CodeAfter
      \tikz{ \draw (1-|1) -- (2-|2);
             \draw (2-|1) -- (3-|2); }
    \end{NiceTabular}
\end{center}

Solution 2, comment out newline(s) in the middle

\begin{center}
  \begin{NiceTabular}[width=10cm]{X[1,l]}[hlines,vlines]
      \RowStyle[cell-space-top-limit=5pt, cell-space-bottom-limit=10pt]{}
      Some text \\
      \RowStyle[cell-space-top-limit=10pt, cell-space-bottom-limit=5pt]{}
      Some text
      \CodeAfter
      \tikz \draw (1-|1) -- (2-|2);%
      \tikz \draw (2-|1) -- (3-|2);
    \end{NiceTabular}
\end{center}

Original, shifted output

\begin{center}
  \begin{NiceTabular}[width=10cm]{X[1,l]}[hlines,vlines]
      \RowStyle[cell-space-top-limit=5pt, cell-space-bottom-limit=10pt]{}
      Some text \\
      \RowStyle[cell-space-top-limit=10pt, cell-space-bottom-limit=5pt]{}
      Some text
      \CodeAfter
      \tikz \draw (1-|1) -- (2-|2);
      \tikz \draw (2-|1) -- (3-|2);
    \end{NiceTabular}
\end{center}

\end{document}

在此处输入图片描述

相关内容