如何将子表的标题与小页面的左边距对齐?

如何将子表的标题与小页面的左边距对齐?

我有一个minipage宽度为 的表格\textwidth。其中minipage还有另外两个minipages宽度为 的表格0.5\textwidth。每个表格都有一个\tabular带标题的环境(使用KOMA-scripts' \captionof命令制作)。我的表格如下所示:

在此处输入图片描述

我希望它看起来像这样:

在此处输入图片描述

即我想将表格的标题(b)与左对齐(嵌套的边距minipage)。

MWE(子表的标题位于内\NewDocumentEnvironment{subtable}{m m b}):

%! TEX program = lualatex

\documentclass[
 fleqn,
 oneside, 
 headings = optiontoheadandtoc,
 fontsize = 12pt, 
 parskip = never,
 numbers = noendperiod,
 captions = abovetable,
 ]{scrbook}

\interdisplaylinepenalty=1000

\usepackage{scrlayer-scrpage}

\usepackage{xifthen}
\usepackage{etoolbox,xpatch}
\usepackage{xparse}

\usepackage{fontspec}
\setmainfont{cmun}[
    Extension=.otf,
    UprightFont=*rm,
    ItalicFont=*ti,
    BoldFont=*bx,
    BoldItalicFont=*bi,
]

\defaultfontfeatures{Ligatures=TeX}

\usepackage{microtype} 
\usepackage{amssymb,amsthm,IEEEtrantools,latexsym,mathdots,mathtools,upgreek,xfrac}

\usepackage[lowtilde]{url}
\usepackage[unicode, colorlinks, bookmarksnumbered]{hyperref}  

\usepackage{polyglossia}
\setdefaultlanguage[variant=american]{english}
    
\let\oldaddcontentsline\addcontentsline
\newcommand{\hidefromtoc}{\renewcommand{\addcontentsline}[3]{}}
\newcommand{\writetotoc}{\let\addcontentsline\oldaddcontentsline}

\newcounter{subtableCounter}
\newcounter{subfigureCounter}
\newcounter{tempCounterForFiguresAndTables}

\NewDocumentEnvironment{subTables}{m m b}
{%
\noindent\begin{minipage}{\textwidth}%
    \centering
    % --- Main table caption ---
    \addtokomafont{captionlabel}{\bfseries}
    \renewcommand*{\tableformat}{\hfil\tablename~\thetable\hfil}
    \renewcommand*{\captionformat}{}
    \setcapindent*{0em}
    \captionof{table}{#1}
    \label{table:#2}
    \setcaphanging % restore regular caption indent for the subcaptions
    % ----------------------------------------
    % --- Set up counter for the subtables ---
    \setcounter{tempCounterForFiguresAndTables}{\value{table}}
    \setcounter{subtableCounter}{1}
    \renewcommand{\thetable}{(\alph{subtableCounter})}
    \renewcommand*{\tableformat}{\thetable\ }
    % ----------------------------------------
        #3
    \end{minipage}
    \par
    %
    % --- Restore table counter to normal ---
    \renewcommand\thetable{\arabic{table}}
    \setcounter{table}{\value{tempCounterForFiguresAndTables}}
}
{}

\NewDocumentEnvironment{subtable}{m m b}
{%
    \noindent\begin{minipage}[t]{0.5\textwidth}%
        {\centering
        #3
        \par}
        %
        % --- Subtable caption ---
        \hidefromtoc
        \vspace*{0.5em}
        \captionof{table}{#1}
        \label{subtable:#2}
        \writetotoc
        \addcontentsline{lot}{table}{\hskip 0.7em\thetable\autodot\ #1}
        \refstepcounter{subtableCounter}
\end{minipage}%
}
{}


\begin{document}
    \listoftables
    \chapter{Test}
    \section{Test}
    \counterwithout{table}{chapter}
    \begin{subTables}{Here we provide a description that is really long for testing purposes. Look how long this description is.}{tagTable1}%
        \begin{subtable}{Another really long description that spans multiple lines.}{tagSubtable1}
            \begin{tabular}{c | r @{.} l} 
                $\sin(x)$ & \multicolumn{2}{c}{value} \\
                \hline
                $\sin(0)$           & 0&0 \\
                $\sin(\frac{\pi}{4})$       & 0&707
            \end{tabular}
        \end{subtable}%
        \begin{subtable}{Description}{tagSubtable2}
            \begin{tabular}{c | r @{.} l} 
                $\cos(x)$ & \multicolumn{2}{c}{value} \\
                \hline
                $\cos(0)$           & 1&0 \\
                $\cos(\frac{\pi}{4})$       & 0&707
            \end{tabular}
        \end{subtable}%
    \end{subTables}%            
\end{document}

答案1

您可以使用\KOMAoptions{captions=nooneline}

\NewDocumentEnvironment{subtable}{m m b}
{%
    \noindent\begin{minipage}[t]{0.5\textwidth}%
        {\centering
        #3
        \par}
        %
        % --- Subtable caption ---
        \KOMAoptions{captions=nooneline}% <- added
        \hidefromtoc
        \vspace*{0.5em}
        \captionof{table}{#1}
        \label{subtable:#2}
        \writetotoc
        \addcontentsline{lot}{table}{\hskip 0.7em\thetable\autodot\ #1}
        \refstepcounter{subtableCounter}
\end{minipage}%
}
{}

答案2

您可以subtable像这样修改环境的定义:

\usepackage{caption}
\NewDocumentEnvironment{subtable}{m m b}
{%
    \noindent\begin{minipage}[t]{0.5\textwidth}%
        {\centering
        #3
        \par}
        %
        % --- Subtable caption ---
\captionsetup{singlelinecheck=off}
        \hidefromtoc
        \vspace*{0.5em}
        \captionof{table}{#1}
        \label{subtable:#2}
        \writetotoc
        \addcontentsline{lot}{table}{\hskip 0.7em\thetable\autodot\ #1}
        \refstepcounter{subtableCounter}
\end{minipage}%

相关内容