长表附加标题缩进

长表附加标题缩进

当标题太长而无法在一行中容纳时,我想要的是如下内容:

Table 1: whateverj lakjsdfñ lkjasdfl kjasñdlf j
         wastathahtaht

Table 1 (cont.): Wahtashetlkahkethjaklthjalkdthjalk
                 lkjwñtjqñjeñtqljetñljk

我曾尝试使用:

\begin{longtable}{c|c}
  \caption{whateverj lakjsdfñ lkjasdfl kjasñdlf j wastathahtaht}
  \label{tab:my}\\
  \toprule
  a & b \\
  \midrule
  \endfirsthead

  \caption*{\textbf{Table \ref{tab:mytab} (cont.):} Wahtashetlkahkethjaklthjalkdthjalk                      lkjwñtjqñjeñtqljetñljk}\\
  \toprule
  a & b \\
  \midrule
  \endhead
  l1 & l2 \\
\end{longtable}

但我得到的却是:

Table 1: whateverj lakjsdfñ lkjasdfl kjasñdlf j
         wastathahtaht

Table 1 (cont.): Wahtashetlkahkethjaklthjalkdthjalk
lkjwñtjqñjeñtqljetñljk

我怎样才能缩进连续标题?我正在使用 KOMA scrbook 和 longtable 包。

答案1

您可以使用 来完成此操作\multicolumn,但效果不如使用\caption*。不过,\LTcapwidth很有用。

\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{blindtext}

\newsavebox{\mycaptionbox}

\newcommand{\myfirstcaption}[1]{\caption*{\savebox{\mycaptionbox}{Table \thetable: }%
  \usebox\mycaptionbox\parbox[t]{\dimexpr \LTcapwidth-\wd\mycaptionbox}{#1}}}

\newcommand{\mycaption}[1]{\caption*{\savebox{\mycaptionbox}{Table \thetable~(cont.): }%
  \usebox\mycaptionbox\parbox[t]{\dimexpr \LTcapwidth-\wd\mycaptionbox}{#1}}}

\begin{document}
\begin{longtable}{c|c}
  \myfirstcaption{\blindtext}
  \label{tab:my}\\
  \toprule
  a & b \\
  \midrule
  \endfirsthead
  \mycaption{\blindtext}\\
  \toprule
  a & b \\
  \midrule
  \endhead
  l1 & l2 \\
  \rule{1em}{29\normalbaselineskip}% too big for first page
\end{longtable}
\end{document}

答案2

这是一个尝试,它使用包longtblr中的环境。tabularray

表输出

\documentclass{scrbook}

\usepackage{lipsum}
\usepackage{booktabs}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\ExplSyntaxOn
\DefTblrTemplate { capcont } { mycaption }
{
    \hbox_set:Nn \l__tblr_caption_box
    {
        \UseTblrTemplate { caption-tag } { default }
        \space
        \UseTblrTemplate { conthead-text } { default }
        \UseTblrTemplate { caption-sep } { default }
        \UseTblrTemplate { caption-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 }
            \space
            \UseTblrTemplate { conthead-text } { 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] [c] { \box_use:N \l__tblr_caption_box }
        \par
    }
}
\ExplSyntaxOff

\SetTblrTemplate{capcont}{mycaption}

\DefTblrTemplate{conthead-text}{default}{(cont.)}

\begin{document}
Extra page to have the correct margins for two page layout
\newpage

\noindent   
\begin{longtblr}[
        caption={This is very very very very very very very very very very very very very very very very very long caption},
        label={tab:my}
    ]{
        colspec={X|X},
        rowhead=1,
    }
    \toprule
    a & b \\
    \midrule
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    l1 & l2 \\
    \bottomrule
\end{longtblr}

\end{document}

但是,标题的宽度等于表格的宽度,如果您的表格较窄,这可能是一个问题。我X在示例中使用了列类型,它使用所有可用空间作为列。如果标题的宽度对您来说是个问题,您可以查看问题。不幸的是,我还不能将自定义对齐和全宽标题结合起来。也许其他人有想法...

相关内容