I found some small problems when using "Redefined TblrTemplates". This redefined template was used to align the longtblr captions to the left.
If the table's caption is long enough, my formatting requires it to hang on the next line. If the table width is equal to the text width, the table caption will hang perfectly on the next line. The problem occurred when the width of the table didn't equal the text width. As you can see, the caption shrunk as the table width decreased.
I did try the solution with the caption package,
\captionsetup{width=1\textwidth}
but it wouldn't work because longtblr operated in its own environment.
I did some research and discovered some answers here. This solution appears to solve the problem with caption width, but for some reason the captions no longer hang. Also, this answer here solved the problem with the caption hanging but also shrank the caption. I failed when I attempted to combine these two methods.
I have insufficient knowledge of programming to modify the Tabularray source code. To achieve a table caption that hung on the next line and had the width of the text width, I'm in great need of help. Any suggestion or answer is appreciated.
\documentclass{article}
\usepackage{tabularray}
\usepackage[singlelinecheck=off]{caption}
\captionsetup[table]{format=hang}
% Redefined TblrTemplates
\ExplSyntaxOn
\DefTblrTemplate{caption}{normal}{
\hbox_set:Nn \l__tblr_caption_box{
\UseTblrTemplate{caption-tag}{default}
\UseTblrTemplate{caption-sep}{default}
\UseTblrTemplate{caption-text}{default}
}
\dim_compare:nNnTF{\box_wd:N \l__tblr_caption_box}>{\hsize}{
\UseTblrAlign{caption}
\UseTblrIndent{caption}
\hbox_set:Nn \l__tblr_caption_left_box{
\UseTblrTemplate{caption-tag}{default}
\UseTblrTemplate{caption-sep}{default}
}
\hangindent=\box_wd:N \l__tblr_caption_left_box
\hangafter=1
\UseTblrHang{caption}
\leavevmode
\hbox_unpack:N \l__tblr_caption_box
\par
}{
\centering
\makebox[\hsize][l]{\box_use:N \l__tblr_caption_box}
\par
}}
\DefTblrTemplate{capcont}{normal}{
\hbox_set:Nn \l__tblr_caption_box{
\UseTblrTemplate{caption-tag}{default}
\UseTblrTemplate{caption-sep}{default}
\UseTblrTemplate{caption-text}{default}
\space
\UseTblrTemplate{conthead-text}{default}
}
\dim_compare:nNnTF{\box_wd:N \l__tblr_caption_box}>{\hsize}{
\UseTblrAlign{capcont}
\UseTblrIndent{capcont}
\hbox_set:Nn \l__tblr_caption_left_box{
\UseTblrTemplate{caption-tag}{default}
\UseTblrTemplate{caption-sep}{default}
}
\hangindent=\box_wd:N \l__tblr_caption_left_box
\hangafter=1
\UseTblrHang{capcont}
\leavevmode
\hbox_unpack:N \l__tblr_caption_box
\par
}{
\centering
\makebox[\hsize][l]{\box_use:N \l__tblr_caption_box}
\par
}}
\SetTblrTemplate{caption}{normal}
\SetTblrTemplate{capcont}{normal}
\ExplSyntaxOff
\begin{document}
\begin{table}[h]
\caption{This is a normal table caption using a table environment. If the table's caption is long enough, the formatting requires it to hang on the next line}
\centering
\begin{tblr}{
width=0.5\linewidth,
colspec={XXX},
hlines, vlines
}
Head & Head & Head \\
Head & Data & Data \\
\end{tblr}
\end{table}
\begin{longtblr}[
caption={This is a long table that uses "Redefined TblrTemplates" suggested by @samcarter\_is\_at\_topanswers.xyz. The table caption was hanging perfectly on the next line with no problems}
]{
colspec={XXX},
hlines, vlines,
rowhead=1
}
Head & Head & Head \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
\end{longtblr}
\begin{longtblr}[
caption={The problem occurred when the width of the table didn't equal the text width. As you can see, the caption shrunk as the table width decreased}
]{
colspec={*3{X[2cm]}},
hlines, vlines,
rowhead=1
}
Head & Head & Head \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
Head & Data & Data \\ Head & Data & Data \\
\end{longtblr}
\end{document}
\leavevmode
insert\hsize=\textwidth
.\centering
or\begin{center}
, but neither worked. Additional guidance would be appreciated.