我试图将长表格的标题居中(longtblr
)但它总是出现在左侧,我使用了包\usepackage[justification=centring]{caption}
并且\captionsetup{justification = centering}
几乎尝试了所有方法但我没有得到我想要的结果。
有人能帮帮我吗?
我添加了一个关于我的工作的例子
\docmentclass{article}
%\usepackage{??}
\NewTblrTheme{fancy}{
\SetTblrStyle{caption-tag}{font=\bfseries}
}
\begin{document}
\begin{longtblr}[theme=fancy,
caption = {obtained results for the work as shown in the table below with test and M from 1 to 16.},
label = {tab:websites},
]{
width = \linewidth,
colspec = {Q[175]Q[150]Q[175]Q[175]Q[175]},
cells = {c},
cell{2}{2} = {r=2}{},
cell{4}{2} = {r=2}{},
cell{6}{2} = {r=2}{},
cell{8}{2} = {r=2}{},
cell{10}{2} = {r=2}{},
cell{12}{2} = {r=2}{},
cell{14}{2} = {r=2}{},
cell{16}{2} = {r=2}{},
vlines,
hline{1-2,4,6,8,10,12,14,16,18} = {-}{},
hline{3,5,7,9,11,13,15,17} = {1,3-5}{},
}
test & test & test & test & test \\
M1 & 90 & 0.63 & 0.71 & 0.67 \\
M2 & & 0.67 & 0.58 & 0.62 \\
M3 & 80 & 0.61 & 0.76 & 0.68 \\
M4 & & 0.68 & 0.51 & 0.58 \\
M5 & 70 & 0.85 & 0.86 & 0.86 \\
M6 & & 0.86 & 0.85 & 0.86 \\
M7 & 65 & 0.92 & 0.93 & 0.92 \\
M8 & & 0.93 & 0.91 & 0.92 \\
M9 & 77 & 0.95 & 0.75 & 0.84 \\
M10 & & 0.79 & 0.96 & 0.87 \\
M11 & 56 & 0.94 & 0.77 & 0.85 \\
M12 & & 0.81 & 0.95 & 0.87 \\
M13 & 89 & 0.87 & 0.82 & 0.84 \\
M14 & & 0.83 & 0.87 & 0.85 \\
M15 & 63 & 0.57 & 0.58 & 0.58 \\
M16 & & 0.57 & 0.57 & 0.57
\end{longtblr}
\end{document}
答案1
- 不完全清楚你的问题是什么。
- 默认情况下,
longtblr
表格中的caption
包对标题格式没有任何影响。 - 长表格使用
longtblr
自己的标题机制,当标题短于表格宽度时,标题居中;当文本较长时,标题悬挂格式化。 - 例如,在前一种情况下,您的表格代码可以是(写得更简洁):
\documentclass{article}
\usepackage{tabularray}
\SetTblrStyle{caption-tag}{font=\bfseries}
\begin{document}
\begin{longtblr}[
caption = {Obtained results for the test M from 1 to 16.},
label = {tab:websites},
]{hlines, vlines,
colspec = { *{5}{X[c]}},
cell{even[2]}{2} = {r=2}{},
row{1} = {font=\bfseries},
rowhead=1
}
test & test & test & test & test \\
M1 & 90 & 0.63 & 0.71 & 0.67 \\
M2 & & 0.67 & 0.58 & 0.62 \\
M3 & 80 & 0.61 & 0.76 & 0.68 \\
M4 & & 0.68 & 0.51 & 0.58 \\
M5 & 70 & 0.85 & 0.86 & 0.86 \\
M6 & & 0.86 & 0.85 & 0.86 \\
M7 & 65 & 0.92 & 0.93 & 0.92 \\
M8 & & 0.93 & 0.91 & 0.92 \\
M9 & 77 & 0.95 & 0.75 & 0.84 \\
M10 & & 0.79 & 0.96 & 0.87 \\
M11 & 56 & 0.94 & 0.77 & 0.85 \\
M12 & & 0.81 & 0.95 & 0.87 \\
M13 & 89 & 0.87 & 0.82 & 0.84 \\
M14 & & 0.83 & 0.87 & 0.85 \\
M15 & 63 & 0.57 & 0.58 & 0.58 \\
M16 & & 0.57 & 0.57 & 0.57 \\
\end{longtblr}
\end{document}
- 但是,当标题测试长于一行并且文本和标题标签应该居中时,您可以通过插入表格标题来使用
caption
包及其隐式格式化可能性:\captionof
\documentclass{article}
\usepackage{tabularray}
\usepackage{caption} % <---
\captionsetup[table]{skip=0pt,
font = {small, sf},
labelfont = bf,
justification=centering % or
% justification=centerlast
}
\NewTblrTheme{captionof}% % <---
{\DefTblrTemplate{caption}{default}%
{\addtocounter{table}{-1}%
\captionof{table}{\InsertTblrText{caption}}%
}
\DefTblrTemplate{capcont}{default}%
{\addtocounter{table}{-1}%
\captionof{table}{\InsertTblrText{caption} (continue)}
}%
}
\begin{document}
\begin{longtblr}[
theme = captionof, % <---
caption = {Obtained results for the test M from 1 to 16. This caption quite text, so it is split at leat into two lines},
label = {tab:websites},
]{hlines, vlines,
colspec = { *{5}{X[c]}},
cell{even[2]}{2} = {r=2}{},
row{1} = {font=\bfseries},
rowhead=1
}
test & test & test & test & test \\
M1 & 90 & 0.63 & 0.71 & 0.67 \\
M2 & & 0.67 & 0.58 & 0.62 \\
M3 & 80 & 0.61 & 0.76 & 0.68 \\
M4 & & 0.68 & 0.51 & 0.58 \\
\end{longtblr}
\end{document}
产生以下结果: