Como o ambiente de mesa longa pode ter que ser modificado para criar um ambiente de quadro longo?

Nov 28 2020

Para contextualizar: Tenho uma longa lista de riscos que quero colocar no meu documento e consegui fazê-lo funcionar usando longtablecomo pode ser visto na foto 1 (está em português porque é a minha dissertação de mestrado).

O problema que estou enfrentando aqui é que longtables são sempre reconhecidos como Tables e eu gostaria de poder usar um float personalizado chamado quadro, que é criado como parte do template que estou usando, definido abaixo:

\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}

Dito isso, como posso editar o longtableambiente para criar um longquadroambiente que não apenas siga a mesma convenção de nomenclatura, mas também seja incluído nas mesmas listas (como Lista de Quadros).

Respostas

2 muzimuzhiZ Nov 28 2020 at 04:57

Como esta é uma questão de acompanhamento de Tentar usar longtable para abranger várias páginas, mas não pode controlar para qual lista ela vai , o exemplo a seguir também é baseado naquele dado na resposta (postada por mim) lá .

Notas gerais:

  • A chave é fazer o patching localmente dentro do ambiente longquadro.
  • Para evitar o problema de aninhamento \xpatchcmd\cmd{<... containing #1>}{}{<true>}{<false>}dentro de uma macro, \LT@c@ptioné redefinido diretamente em vez de corrigido.
% for https://tex.stackexchange.com/q/572654/79060
\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@i\patch@longtable@ii
   \longtable}
  {\endlongtable}

% patching codes base on https://tex.stackexchange.com/a/548021
\newcommand\patch@longtable@i{%
  \xpatchcmd\ltcaption@ORI@LT@array
    {\refstepcounter{table}}
    {\refstepcounter{quadro}}
    {}{\fail}%
}

% since "\@ifpackageloaded" is preamble only, the patching codes have to
% be split in two macros
\@ifpackageloaded{caption}{
  % handle compatibility with caption package
  \newcommand\patch@longtable@ii{%
    \renewcommand\LTcaptype{quadro}%
  }
}{
  \newcommand\patch@longtable@ii{%
    % derectly 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}

3 egreg Nov 28 2020 at 04:57

Isso deve funcionar:

\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}

Verifique as alterações que fiz em seu código.