命令 \fillwithdottedlines (取自考試文檔類別)在表格 (Tabularray) 中不起作用。為什麼?可以修復嗎?

命令 \fillwithdottedlines (取自考試文檔類別)在表格 (Tabularray) 中不起作用。為什麼?可以修復嗎?

我有以下文檔,它是一個表格(tabularray),我想用空虛線填充它。我已經定義了命令,\fillwithdottedlines如您在 MWE 中看到的那樣。儘管該命令在外部tblr環境中完美運行,但在內部環境中卻不起作用。為什麼會發生這種情況以及如何解決它?請在表中取消註釋帶有此命令的行以查看錯誤。

\documentclass[12pt]{article}
\usepackage[a4paper, total={180mm,257mm},left=15mm,top=20mm]{geometry}
\usepackage{tabularray}
\makeatletter
\newlength\dottedlinefillheight
\setlength\dottedlinefillheight{9mm}

\def\fillwithdottedlines#1 {%
    \begingroup
    \ifhmode
    \par
    \fi
    \hrule height \z@
    \nobreak
    \setbox0=\hbox to \hsize{\hskip \@totalleftmargin
        \vrule height \dottedlinefillheight depth \z@ width \z@
        \dotfill}%
    \cleaders \copy0 \vskip #1 \hbox{}%
    \endgroup
}
\makeatother

\begin{document}
    \begin{tblr}{colspec={Q[0.5\linewidth-5pt,c]X[c]},row{1,2}={1cm,m},row{3}={15cm,m},vlines,hlines}
        \SetCell[c=2]{c} \large \textbf{TITLE}                                      \\ 
        \textbf{Subtitle 1}             & \textbf{Subtitle 2}                       \\
                                        &                                           \\
        %\fillwithdottedlines{10cm}     &  \fillwithdottedlines{10cm}               \\
    \end{tblr}

\fillwithdottedlines{5cm}
    
\end{document}

答案1

我不完全確定這裡到底出了什麼問題(因此這只是部分答案),但至少其中一個問題源於其定義\fillwithdottedlines要求參數後面有一個空格(因為空格界定了參數) 。您可以透過寫入左列中的一個儲存格來檢查這一點\fillwithdottedlines{5cm} {},這至少不會導致錯誤,但在垂直對齊方面仍然是次優輸出。由於某些原因我無法解釋,但可能由於其tblr構造方式,此技巧不適用於右列中的單元格。

然而,一個解決方案是將\fillwithdottedlines巨集包裝在 中\parbox,例如使用\parbox{\linewidth}{\fillwithdottedlines{2cm} }.請注意最後一個右大括號之前所需的空間!

\documentclass[12pt]{article}
\usepackage[a4paper, total={180mm,257mm}, left=15mm, top=20mm]{geometry}
\usepackage{tabularray}

\makeatletter
\newlength\dottedlinefillheight
\setlength\dottedlinefillheight{9mm}

\def\fillwithdottedlines#1 {%
    \begingroup
    \ifhmode
    \par
    \fi
    \hrule height \z@
    \nobreak
    \setbox0=\hbox to \hsize{\hskip \@totalleftmargin
        \vrule height \dottedlinefillheight depth \z@ width \z@
        \dotfill}%
    \cleaders \copy0 \vskip #1 \hbox{}%
    \endgroup
}
\makeatother

\begin{document}
    \begin{tblr}{
        colspec = { Q[0.5\linewidth-5pt, c] X[c] },
        row{1,2} = {1cm, m},
        row{3} = {15cm, m},
        vlines,
        hlines,
    }
        \SetCell[c=2]{c} \large \textbf{TITLE}                                      \\ 
        \textbf{Subtitle 1}             & \textbf{Subtitle 2}                       \\
                                        &                                           \\
        \parbox{\linewidth}{\fillwithdottedlines{2cm} } &  
        \parbox{\linewidth}{\fillwithdottedlines{2cm} }                             \\
    \end{tblr}
    
%\fillwithdottedlines{5cm}

\end{document}

在此輸入影像描述

相關內容