%20%E4%B8%AD%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8%E3%80%82%E7%82%BA%E4%BB%80%E9%BA%BC%EF%BC%9F%E5%8F%AF%E4%BB%A5%E4%BF%AE%E5%BE%A9%E5%97%8E%EF%BC%9F.png)
我有以下文檔,它是一個表格(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}