![乳膠桌缺少邊框線](https://rvso.com/image/461891/%E4%B9%B3%E8%86%A0%E6%A1%8C%E7%BC%BA%E5%B0%91%E9%82%8A%E6%A1%86%E7%B7%9A.png)
當將 Latex Table 程式碼從一本期刊移植到 springer 格式時,我再次缺少邊框線(附圖)。 Latex程式碼如下。請建議解決缺少邊框和自動換行以適應頁面寬度的解決方案,而不是我使用的手動解決方案\\
\usepackage{adjustbox}
%\usepackage{tabularx}
\usepackage{tabularx,ragged2e}
\documentclass{sn-jnl}
\begin{document}
\begin{table*}[!h]
%\tiny
\centering
\small
\caption{Result}
\begin{tabular}{|c|c|c|c|}
\hline
\multicolumn{1}{|l|}{\begin{tabular}[c]{@{}l@{}}Users Set\\Size (USS)\end{tabular}} & \multicolumn{1}{l|}{\begin{tabular}[c]{@{}l@{}} Range of Users \\ Individual \end{tabular}} & \multicolumn{1}{l|}{\begin{tabular}[c]{@{}l@{}}Index of scalar array \\ for mapping\end{tabular}} & \multicolumn{1}{l|}{\begin{tabular}[c]{@{}l@{}}Transfer \\ Failure\end{tabular}} \\ \hline
\multirow{6}{*}{6} & \multirow{2}{*}{6} & 10 & 23 \\ \cline{3-4}
& & 4 & \textbf{18.3} \\ \cline{2-4}
& \multirow{2}{*}{7} & 0 & 13.3 \\ \cline{3-4}
& & 4 & \textbf{33.3} \\ \cline{2-4}
& \multirow{2}{*}{7} & 1 & 17 \\ \cline{3-4}
& & 2 & \textbf{66.6} \\ \hline
\end{tabular}
\end{table}
\end{document}
答案1
使用tabularray
和siunitx
包時,垂直線的問題被消除,最後一列中的數字在小數點對齊:
\documentclass{sn-jnl}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\begin{document}
\begin{table*}[ht]
\caption{Result}
\sisetup{table-format=2.1,
detect-weight, % <--
}
\begin{tblr}{hlines, vlines,
colspec = {X[c] X[1.2,c] X[1.8,c] X[c, si]},
cell{even}{2} = {r=2}{},
cell{odd[3]}{Z} = {font=\bfseries},
row{1} = {guard}
}
Users Set Size (USS)
& Range of Users Individual
& Index of scalar array for mapping
& Transfer Failure \\
\SetCell[r=6]{c} 6
& 6 & 10& 23 \\
& & 4 & 18.3 \\
& 7 & 0 & 13.3 \\
& & 4 & 33.3 \\
& 7 & 1 & 17 \\
& & 2 & 66.6 \\
\end{tblr}
\end{table*}
\end{document}
答案2
問題在於文檔類別sn-jnl
(2019/11/18 v0.1,第 1333 行)定義了\let\cline\cmidrule
.然而,此時,\cmidrule
仍然是未定義的,因為此時套件booktabs
尚未載入。這將導致錯誤,因為\cline
未定義。這實際上應該被認為是文檔類別程式碼中的一個錯誤。您可以透過在使用之前載入booktabs
套件來解決此錯誤(之前不起作用)。\RequirePackage{booktabs}
\documentclass
\usepackage
\documentclass
然而,撇開這個內建錯誤不談,文檔類的作者顯然希望您使用booktabs
以下套件:不支援垂直線。使用這個套件提供的宏,其中還有\cmidrule
,插入一些垂直間距,這打破了垂直規則。該類別sn-jnl
現在設定\cline
為 的別名\cmidrule
,這就是為什麼您會得到這些損壞的邊框。
有兩種方法可以解決這個問題。第一種方法是遵循該包的作者可能的意圖並接受該booktabs
包提供的功能,即避免使用垂直線,甚至可能不使用\multirow
s:
\documentclass{sn-jnl}
\begin{document}
\begin{table*}[!h]
\centering
\small
\caption{Result}
\begin{tabular}{ c c c c }
\toprule
\begin{tabular}{@{}l@{}} Users Set \\ Size (USS) \end{tabular} &
\begin{tabular}{@{}l@{}} Range of Users \\ Individual \end{tabular} &
\begin{tabular}{@{}l@{}} Index of scalar array \\ for mapping \end{tabular} &
\begin{tabular}{@{}l@{}} Transfer \\ Failure \end{tabular} \\
\midrule
6 & 6 & 10 & 23 \\ \cline{3-4}
& & 4 & \textbf{18.3} \\ \cline{2-4}
& 7 & 0 & 13.3 \\ \cline{3-4}
& & 4 & \textbf{33.3} \\ \cline{2-4}
& 7 & 1 & 17 \\ \cline{3-4}
& & 2 & \textbf{66.6} \\
\bottomrule
\end{tabular}
\end{table*}
\end{document}
另一種更古怪的方法是\cline
在載入文件類別之前儲存原始宏,然後恢復 的定義\cline
:
\let\clineorig\cline
\documentclass{sn-jnl}
\usepackage{multirow}
\begin{document}
\begin{table*}[!h]
\centering
\small
\caption{Result}
\let\cline\clineorig
\begin{tabular}{|c|c|c|c|}
\hline
\begin{tabular}{@{}l@{}} Users Set \\ Size (USS) \end{tabular} &
\begin{tabular}{@{}l@{}} Range of Users \\ Individual \end{tabular} &
\begin{tabular}{@{}l@{}} Index of scalar array \\ for mapping \end{tabular} &
\begin{tabular}{@{}l@{}} Transfer \\ Failure \end{tabular} \\
\hline
\multirow{6}{*}{6} & \multirow{2}{*}{6} & 10 & 23 \\ \cline{3-4}
& & 4 & \textbf{18.3} \\ \cline{2-4}
& \multirow{2}{*}{7} & 0 & 13.3 \\ \cline{3-4}
& & 4 & \textbf{33.3} \\ \cline{2-4}
& \multirow{2}{*}{7} & 1 & 17 \\ \cline{3-4}
& & 2 & \textbf{66.6} \\
\hline
\end{tabular}
\end{table*}
\end{document}
我個人會推薦第一個解決方案。
至於換行:巢狀是完全可以的tabulars
,但不需要將它們放在\multicolumn
巨集中。我在這方面簡化了程式碼。另一種方法是套用p{}
允許斷行的列類型,但您需要告訴 LaTeX 列的寬度(例如,p{1cm}
列寬為 1 公分)。
答案3
有關信息,請參閱此處您通過使用{NiceTabular}
而不是獲得的內容{tabular}
。
我已加載
nicematrix
但\usepackage{nicematrix}
使用nicematrix
並且pgf
在類中sn-jnl
必須pgf
加載前(\documentclass
與\RequirePackage
)。我已將
\begin{tabular}
and替換end{tabular}
為\begin{NiceTabular}
and\end{NiceTabular}
。
\RequirePackage{pgf}
\documentclass{sn-jnl}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{|c|c|c|c|}
\hline
\multicolumn{1}{|l|}{\begin{tabular}[c]{@{}l@{}}Users Set\\Size (USS)\end{tabular}} & \multicolumn{1}{l|}{\begin{tabular}[c]{@{}l@{}} Range of Users \\ Individual \end{tabular}} & \multicolumn{1}{l|}{\begin{tabular}[c]{@{}l@{}}Index of scalar array \\ for mapping\end{tabular}} & \multicolumn{1}{l|}{\begin{tabular}[c]{@{}l@{}}Transfer \\ Failure\end{tabular}} \\ \hline
\multirow{6}{*}{6} & \multirow{2}{*}{6} & 10 & 23 \\ \cline{3-4}
& & 4 & \textbf{18.3} \\ \cline{2-4}
& \multirow{2}{*}{7} & 0 & 13.3 \\ \cline{3-4}
& & 4 & \textbf{33.3} \\ \cline{2-4}
& \multirow{2}{*}{7} & 1 & 17 \\ \cline{3-4}
& & 2 & \textbf{66.6} \\ \hline
\end{NiceTabular}
\end{document}
這些規則沒有被破壞,因為在 的環境中nicematrix
,被重新定義(並且該定義在本地覆蓋了由 完成cline
的重新定義)。\ncline
sn-jnl
但是,{NiceTabular}
建構表格的標準方法(使用 的工具nicematrix
)如下。
\RequirePackage{pgf}
\documentclass{sn-jnl}
\usepackage{nicematrix}
\usepackage{siunitx}
\begin{document}
\sisetup{table-format = 2.1,detect-weight}
\begin{NiceTabular}{cccS}[hvlines]
\Block[l]{}{Users Set\\ Size (USS)}
& \Block[l]{}{Range of Users\\ Individual}
& \Block[l]{}{Index of scalar array\\ for mapping}
& \Block[l]{}{Transfer\\ Failure} \\
\Block{6-1}{6} & \Block{2-1}{6} & 10 & 23 \\
& & 4 & \bfseries 18.3 \\
& \Block{2-1}{7} & 0 & 13.3 \\
& & 4 & \bfseries 33.3 \\
& \Block{2-1}{7} & 1 & 17 \\
& & 2 & \bfseries 66.6 \\
\end{NiceTabular}
\end{document}