使用“captionsetup”重命名表格并将新名称保留在目录中,而不是将其改回“table”

使用“captionsetup”重命名表格并将新名称保留在目录中,而不是将其改回“table”

我尝试使用 caption 包的 captionsetup 选项在本地将两个表重命名为“overview”,并最终希望它们以这个新名称出现在表列表 (LOT) 中。但是,名称在 LOT 中被切换回“table”。有没有办法将更改后的名称包含在 LOT 中?我考虑过“newfloat”包,但我想让重命名的表出现在表列表中而不是单独的列表中,这似乎更难实现。(此外,在概览列表中,两个概览显示为“table”)。

在下面找到一个简化的示例,任何帮助都非常感谢。谨致问候

\documentclass[a4paper, 11pt, draft]{article}

\usepackage{geometry}
\geometry{a4paper, top=2.54cm, left=4.32cm, right=2.29cm, bottom=2.03cm,headsep=10mm, footskip=12mm}  
\usepackage[onehalfspacing]{setspace} 

%language  
\usepackage [ngerman,english]{babel} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%font
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

%TOC etc
\usepackage{tocloft}
\usepackage{titletoc}
\setlength{\cftfignumwidth}{1.5em} 
\setlength{\cfttabnumwidth}{1.5em}  
\setlength{\cftsubsecindent}{4em}
\setlength{\cftsecnumwidth}{2.5em}
\setlength{\cftsubsecnumwidth}{2.5em}
\renewcommand{\cftfigfont}{Figure }
\renewcommand{\cfttabfont}{Table } 
\renewcommand{\cfttabaftersnumb}{\hspace*{-2em}}
\renewcommand{\cftfigaftersnumb}{\hspace*{-2em}}

\usepackage{tabularx}
\usepackage{caption}
\usepackage{lipsum}


\begin{document}

\listoftables

\lipsum

{
\captionsetup[table]{name=Overview}
\begin{table}
    \caption{some caption to clearly outline what is going on below. Also elongated to see how the caption will float over the table/overview environment, lalala, so long caption, sososo long caption, some more text and even more.}
    \begin{tabularx}{\textwidth}{|rX|}
    \hline
    1. & \textbf{Some Text.} Some more text of this overview. \\
    \hline
    2. & \textbf{Some Text.} Some more text of this overview. \\
    \hline  
    \end{tabularx}
\end{table}
}

{
\setcounter{table}{0}
\begin{table}[ht!]
    \caption{some other caption to clearly outline what is going on below. Also elongated to see how the caption will float over the table/overview environment, lalala, so long caption, sososo long caption, some more text and even more.}
    \begin{tabularx}{\textwidth}{r|X}
    entry 1 & entry 2 \\
    \hline
    A. & 1000 \\
    B. & 2000 \\
    \hline      
    \end{tabularx}
\end{table}
}


\end{document}

答案1

使用该caption包,你可以定义自己的字幕列表格式

\DeclareCaptionListFormat{name}{code using #1 and #2}

对于这个例子,定义了两种格式:(a)用于概述,(b)用于普通表。

b

% !TeX TS-program = pdflatex

\documentclass[a4paper, 11pt, draft]{article}

\usepackage{geometry}
\geometry{a4paper, top=2.54cm, left=4.32cm, right=2.29cm, bottom=2.03cm,headsep=10mm, footskip=12mm}  
\usepackage[onehalfspacing]{setspace} 

%language  
\usepackage [ngerman,english]{babel} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%font
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

%TOC etc
\usepackage{tocloft}
\usepackage{titletoc}
\setlength{\cftfignumwidth}{1.5em} 
\setlength{\cfttabnumwidth}{1.5em}  
\setlength{\cftsubsecindent}{4em}
\setlength{\cftsecnumwidth}{2.5em}
\setlength{\cftsubsecnumwidth}{2.5em}
\renewcommand{\cftfigfont}{}
\renewcommand{\cfttabfont}{} % Use for font changes changed <<<<<<<<<<<<<<<<<<<<<<<<<<<<
\renewcommand{\cfttabaftersnumb}{\hspace*{-2em}}
\renewcommand{\cftfigaftersnumb}{\hspace*{-2em}}

\usepackage{tabularx}
\usepackage{lipsum}

\usepackage{caption}
%******************************************************* added <<<<<<<<<<<<
\DeclareCaptionListFormat{overviewformat}{Overview~#1~#2} 
\DeclareCaptionListFormat{simpletable}{Table~#1~#2}
\renewcommand{\numberline}[1]{#1\quad}
\captionsetup[table]{listformat=simpletable} % used for regular tables<<<<<<<<<<
%*******************************************************

\begin{document}
    
    \listoftables
    
    \lipsum
    
{\captionsetup[table]{listformat=overviewformat} % added <<<<<<<<<<
    \renewcommand{\tablename}{Overview} % added <<<<<<<<<<
        \begin{table}
            \caption{some caption to clearly outline what is going on below. Also elongated to see how the caption will float over the table/overview environment, lalala, so long caption, sososo long caption, some more text and even more.}
            \begin{tabularx}{\textwidth}{|rX|}
                \hline
                1. & \textbf{Some Text.} Some more text of this overview. \\
                \hline
                2. & \textbf{Some Text.} Some more text of this overview. \\
                \hline  
            \end{tabularx}
        \end{table}
    }
    
    {%
        \setcounter{table}{0}
        \begin{table}[ht!]
            \caption{some other caption to clearly outline what is going on below. Also elongated to see how the caption will float over the table/overview environment, lalala, so long caption, sososo long caption, some more text and even more.}
            \begin{tabularx}{\textwidth}{r|X}
                entry 1 & entry 2 \\
                \hline
                A. & 1000 \\
                B. & 2000 \\
                \hline      
            \end{tabularx}
        \end{table}
    }   
    
\end{document}

相关内容