如何修改 longtable 环境来创建 longquadro 环境?

如何修改 longtable 环境来创建 longquadro 环境?

提供一些背景信息:我有一长串的风险清单,我想把它们放在我的文档中,并设法让它发挥作用,longtable如图 1 所示(它是葡萄牙语,因为这是我的硕士论文)。

在此处输入图片描述

我在这里面临的问题是,长表总是被识别为表,我希望能够使用一个名为的自定义浮点数quadro,它是作为我正在使用的模板的一部分创建的,定义如下:

\newcommand{\listquadroname}{Lista de quadros}
\newcommand{\quadroname}{Quadro}
\newcommand{\quadrorefname}{Quadro}
\newcommand{\chartautorefname}{Quadro}

\addto\captionsenglish{% ingles
    \renewcommand{\listquadroname}{List of charts}
    \renewcommand{\quadroname}{Chart}
    \renewcommand{\quadrorefname}{Chart}
    \renewcommand{\chartautorefname}{Chart}
}

\newfloat{quadro}{htbp}{loq}[chapter]
\floatname{quadro}{\quadroname}
\floatstyle{plaintop}
\restylefloat{quadro}
\newlistof{listofquadros}{loq}{\listquadroname}
\newlistentry{quadro}{loq}{0}
\renewcommand{\thequadro}{\thechapter.\@arabic\c@quadro}
\setfloatadjustment{quadro}{\centering}

\renewcommand{\cftquadroname}{\quadroname\space}
\renewcommand*{\cftquadroaftersnum}{\hfill\textendash\hfill}

\begin{quadro}[htb]
\caption{Editores de Texto Livres}
\label{quadro:editores_texto_livres}
\centering
\begin{tabular}{|l|l|r|}        \hline
Editor     & Multiplataforma & Específico para Latex \\ \hline
Kwriter    & Sim             & Não                   \\
Texmaker   & Sim             & Sim                   \\
Kile       & Sim             & Sim                   \\
Geany      & Sim             & Não                   \\ \hline
\end{tabular}
\end{quadro}

话虽如此,我该如何编辑longtable环境来创建一个longquadro不仅遵循相同命名约定而且包含在相同列表(如 Quadros 列表)中的环境。

答案1

由于这是尝试使用 longtable 使其跨越多个页面,但无法控制它进入哪个列表,下面的例子也是基于那里的答案(我自己发布的)中给出的例子。

一般注意事项:

  • 关键是在环境内部本地进行修补longquadro
  • \xpatchcmd\cmd{<... containing #1>}{}{<true>}{<false>}为了避免宏内部嵌套的问题,\LT@c@ption直接重新定义而不是修补。
% for https://tex.stackexchange.com/q/572654
\documentclass{report}

\usepackage[strut=off]{caption}
\usepackage{float}
\usepackage{longtable}
\usepackage{xpatch}

\newcommand{\listquadroname}{Lista de quadros}
\newcommand{\quadroname}{Quadro}
\newcommand{\quadrorefname}{Quadro}
\newcommand{\chartautorefname}{Quadro}

\newfloat{quadro}{htbp}{loq}[chapter]
\floatname{quadro}{\quadroname}
\floatstyle{plaintop}
\restylefloat{quadro}

\makeatletter
\renewcommand{\thequadro}{\thechapter.\@arabic\c@quadro}

% define env "longquadro"
\newenvironment{longquadro}
  {\patch@longtable
   \longtable}
  {\endlongtable}

% based on https://tex.stackexchange.com/a/548021
\@ifpackageloaded{caption}{
  \newcommand\patch@longtable{%
    \xpatchcmd\ltcaption@ORI@LT@array
      {\refstepcounter{table}}
      {\refstepcounter{quadro}}
      {}{\fail}%
    \renewcommand\LTcaptype{quadro}%
  }
}{
  \newcommand\patch@longtable{%
    \xpatchcmd\LT@array
      {\refstepcounter{table}}
      {\refstepcounter{quadro}}
      {}{}%
    % directly redefine "\LT@c@ption"
    \def\LT@c@ption##1[##2]##3{%
      \LT@makecaption##1\fnum@quadro{##3}%
      \def\@tempa{##2}%
      \ifx\@tempa\@empty\else
         {\let\\\space
         \addcontentsline{loq}{quadro}{\protect\numberline{\thequadro}{##2}}}%
      \fi}%
  }
}
\makeatother


\begin{document}
\listoftables
\listof{quadro}{\listquadroname}

\chapter{title}

\begin{table}[htb]
  \caption{This is s table title}
\end{table}

\begin{quadro}[htb]
  \caption{This is a quadro title}
\end{quadro}

\begin{longtable}{cc}
  \caption{This is a longtable title} \\
  a & b \\
  c & d
\end{longtable}

\begin{longquadro}{cc}
  \caption{This is a longquadro title} \\
  a & b \\
  c & d
\end{longquadro}
\end{document}

表格列表 四角星名单 第 1 章,四个(长)表状环境

答案2

这应该有效:

\documentclass{abntex2}

\usepackage{float}
\usepackage{longtable}
\usepackage{xpatch}

%%changed to make generic
\providecommand{\listquadroname}{}
\providecommand{\quadroname}{}
\providecommand{\quadrorefname}{}
\providecommand{\chartautorefname}{}

\addto\captionsbrazil{%
  \renewcommand{\listquadroname}{Lista de quadros}%
  \renewcommand{\quadroname}{Quadro}%
  \renewcommand{\quadrorefname}{Quadro}%
  \renewcommand{\chartautorefname}{Quadro}%
}

\addto\captionsenglish{%
  \renewcommand{\listquadroname}{List of charts}%
  \renewcommand{\quadroname}{Chart}%
  \renewcommand{\quadrorefname}{Chart}%
  \renewcommand{\chartautorefname}{Chart}%
}
%%%

\newfloat{quadro}{htbp}{loq}% <--- changed
\counterwithin{quadro}{chapter}% <--- added
\floatname{quadro}{\quadroname}
\floatstyle{plaintop}
\restylefloat{quadro}
\newlistof{listofquadros}{loq}{\listquadroname}
\newlistentry{quadro}{loq}{0}
\renewcommand{\thequadro}{\thechapter.\arabic{quadro}}% <--- changed
\setfloatadjustment{quadro}{\centering}

\renewcommand{\cftquadroname}{\quadroname\space}
\renewcommand*{\cftquadroaftersnum}{\hfill\textendash\hfill}

\makeatletter
\newenvironment{longquadro}
 {%
  \let\c@table\c@quadro\let\thetable\thequadro
  \def\fnum@table{\quadroname{ }\thequadro}%
  \xpatchcmd{\NRorg@LT@c@ption}{{lot}{table}}{{loq}{quadro}}{}{}%
  \xpatchcmd{\NRorg@LT@c@ption}{{lot}{table}}{{loq}{quadro}}{}{}%
  \renewcommand{\theHtable}{quadro\thechapter.\arabic{quadro}}%
  \longtable
 }
 {\endlongtable}
\makeatother

\begin{document}

\listofquadros

\chapter{First}

\begin{quadro}[htp]
\caption{Test}
\end{quadro}

\begin{longquadro}{|l|l|r|}
\caption{Editores de Texto Livres}
\label{quadro:editores_texto_livres}\\
\hline
Editor     & Multiplataforma & Específico para Latex \\ \hline
Kwriter    & Sim             & Não                   \\
Texmaker   & Sim             & Sim                   \\
Kile       & Sim             & Sim                   \\
Geany      & Sim             & Não                   \\ \hline
\end{longquadro}

\end{document}

在此处输入图片描述

检查我对你的代码所做的更改。

相关内容