4

To give some context: I have a long list of risks I want to put in my document and managed to make it work using longtable as can be seen in pic1 (It's in portuguese because it's my masters disstertaion).

enter image description here

The problem I'm facing here is that longtables are always recognized as Tables and I would like to be able to use a custom float named quadro, that is created as part of the template I'm using which is defined below:

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

That being said, how might I edit the longtable environment to create a longquadro environment that not only follows the same naming convention but also is included in the same lists (like List of Quadros).

Zarko
  • 296,517
  • 1
    This appears to be a duplicate of the question you just asked https://tex.stackexchange.com/questions/572550/how-to-make-a-combined-list-of-quadros you can edit a question if it needs clarification, better than re-posting as a new question leaving both open. – David Carlisle Nov 27 '20 at 21:28
  • 2
    also please post examples as complete documents that people can copy and run to see the issue, – David Carlisle Nov 27 '20 at 21:29
  • 2
    @DavidCarlisle - this posting isn't a full duplicate of the OP's earlier query (even though large parts of it are), which I answered. I suggested to the OP that he should post a new query to ask specifically about creating a longquadro environment that is to the quadro environment (defined with the help of the newfloat package) what the longtable environment is to the table environment. – Mico Nov 27 '20 at 21:37
  • 1
    @Mico OK (this is built in to v5 actually, but v5 isn't going to appear any time soon) – David Carlisle Nov 27 '20 at 21:57

2 Answers2

3

This should work:

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

enter image description here

Check the changes I made to your code.

egreg
  • 1,121,712
  • Update here, @egreg When Importing this config to my template the numbers worked perfectly but then I noticed that the quadrolist was skipping those quadros. After a LOT of testing and removing things in a test doc I found out I had this package: \usepackage{caption} which were overwriting the new macro and not adding the content to the loq. Is there a way to keep this package on without loosing your fix? If I remove it it breaks a bunch of other things. – Victor Archela Nov 30 '20 at 08:31
  • do you know anything that might help? I might open a new question just for this but wanted to check either way – Victor Archela Dec 13 '20 at 20:25
  • @VictorArchela Since caption modifies the meaning of \caption, one has to do a different patch. Following all the redefinitions is quite cumbersome. On the other hand, abntex2 is based on memoir that has its own method for modifying captions and dealing with subfloats. – egreg Dec 13 '20 at 21:02
2

Since this is a follow-up question of Trying to use longtable to make it span multiple pages but can't control to which list it goes to, the following example is also based on the one given in the answer (posted by myself) there.

General notes:

  • The key is to do the patch locally inside environment longquadro.
  • To avoid the problem of nesting \xpatchcmd\cmd{<... containing #1>}{}{<true>}{<false>} inside a macro, \LT@c@ption is directly redefined rather than patched.
% 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}

list of tables Lista de quadros chapter 1, four (long)table-like envs

muzimuzhi Z
  • 26,474
  • thanks @muzimuzhi once again being quick to propose an answer :) – Victor Archela Nov 27 '20 at 22:27
  • I have tested the code but adding it to an empty overleaf project gives me an error when it comes to using the \AddToHook. Is it something I can change in the doc?

    The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

    I don't want you to spent to much time thought because the above solution did work.

    – Victor Archela Nov 27 '20 at 22:36
  • 1
    @VictorArchela Answer edited. The depending on latex2e 2020-10-01, a latex2e version that Overleaf hasn't provided yet, is removed. – muzimuzhi Z Nov 27 '20 at 22:51
  • Works now thanks @muzimuzi! – Victor Archela Nov 27 '20 at 22:59
  • Hey @Muzimuzi, I have an update on the question here. The numbers work perfectly but I had a problem bringing it into my template because it changes the formatting of the list of quadros. Because \listofquadros is empty and you recommended the use of \listof{quadro}{\listquadroname}. The thing is a list entry in the template looks like this: "Quadro 1 - Name of the quadro . . . . . pagenumber". Is there a way to go back to using \listofquadros while having the caption package? – Victor Archela Nov 30 '20 at 08:35
  • 1
    @VictorArchela If the output of list-of-quadros entry is OK, but you prefer \listofquadros, just \newcommand\listofquadros{\listof{quadro}{\listquadroname}}. – muzimuzhi Z Nov 30 '20 at 14:13
  • I am currently testing this snippet, but it breaks with

    `! Undefined control sequence. \fail

    l.174 \begin{longquadro} {cc} ?`

    I don't know where to look.

    – Gabriel Araújo Nov 06 '21 at 18:08
  • @GabrielAraújo Which version of latex (or texlive) do you use? Just double checked with my local updated texlive 2021 and overleaf.com's texlive 2020&21, the snippet compiles with no errors. Maybe you dropped the \makeatletter and/or \makeatother? – muzimuzhi Z Nov 06 '21 at 18:41
  • @muzimuzhiZ, I use TeX Live 2021/Arch Linux, kpathsea version 6.3.3. I notice that this checking always fail \xpatchcmd\ltcaption@ORI@LT@array {\refstepcounter{table}} {\refstepcounter{quadro}} {}{\fail}%. So I removed the \fail command, and it works. But I know that it is not the right thing to do. – Gabriel Araújo Nov 06 '21 at 21:47
  • @GabrielAraújo Answer updated. If your example doesn't load caption, then that incompatibility should be fixed. – muzimuzhi Z Nov 06 '21 at 22:09