davidcarlisle / dpctex

Assorted TeX packages
94 stars 30 forks source link

longtable, xltabular and enumerate #57

Open hvoss49 opened 1 month ago

hvoss49 commented 1 month ago

Wrong counter with latest long table:

\documentclass{article}
%\usepackage{longtable-2020-01-07}
\usepackage{longtable}
\usepackage{xltabular}

\begin{document}

\begin{longtable}{ | l | p{5in} |}\hline
    Rev 1 &
    \begin{enumerate} %\setcounter{enumi}{1}
        \item 9/20/2024: AA
        \item 9/24/2024: BB
    \end{enumerate}
    \\ \hline
  \end{longtable}

\end{document}

The counter starts at 0, without loading xltabular at the expected 1. If I load longtable from 2020 (needs also the change in ltablex.sty) all is fine! I cannot see why the latest longtable maybe a problem. xltabular only loads tabularx, longtable and ltablex

Tested with Up-to-date TL2024

hvoss49 commented 3 weeks ago

ping ...

davidcarlisle commented 3 weeks ago

I'll look, note that longtable 4.x as distributed on ctan is in the latex2e repository (core tools release) this repo has a more speculative longtable v5 code that may or may not get released one day.

davidcarlisle commented 3 weeks ago

I'll move this to tools, even though it needs additional packages it is certainly a change in longtable. hmm I can't move the issue.

davidcarlisle commented 3 weeks ago

the new longtable has extended caption support (from ltcaption) which was needed for tagging, this has adjusted \refstepcounter usage and means xltabulars patch to make \refstepcounter do nothing on the first call is stopping the enumeration counter rather than the table counter. If you comment out this part

\def\LT@array{%
    % make the call of \refstepcounter inside of \XLT@LT@array ineffective
    % \renewcommand*\refstepcounter[2][]{%
      % make next calls effective again
   %   \let\refstepcounter=\XLT@refstepcounter
    %}%
    \XLT@LT@array

The example works with the list starting at 1, but I haven't traced everything xltabular is doing here. Looking....

davidcarlisle commented 3 weeks ago

@hvoss49 I'm not entirely sure if you need that refstepcounter patch at all with the new version, it would need some adjustment as longtable doesn't call \refstepcounter caption code generallly (not just longtable) is being adjusted to separately set the anchor and increment the counter to get better linking and tagging without requiring hyperref to patch everything.

See the discussion at https://github.com/latex3/latex2e/issues/1377 (as I mentioned the extended caption support is based on that discussion)

hvoss49 commented 3 weeks ago

Thanks David, it looks like a useful patch. I had to remember why we had the redefinition of \refstepcounter.

anyway, with some further tests I'll apply your fix.

hvoss49 commented 1 week ago

David, it solved one issue, but creates a new one (caption starts at "Table 2"):

\documentclass{book}
\usepackage{xltabular}
\begin{document}
\begin{longtable}{c}
\caption{caption}
\endfirsthead
xxx\\xxx
xxx\\xxx
\end{longtable}
\end{document}

Do you have another idea? The current TL2024 xltabular has your above patch:

  \def\LT@array{%
    % make the call of \refstepcounter inside of \XLT@LT@array ineffective
%    \renewcommand*\refstepcounter[2][]{%
      % make next calls effective again
%      \let\refstepcounter=\XLT@refstepcounter
%    }%
    \XLT@LT@array
  }% 

Reverting it, solves the new problem but has the old one with enumerate.

u-fischer commented 1 week ago

@hvoss49 I just wanted to comment in the issue: It seems to work if one reinstate the default caption definition of longtable (or avoid to change it):

\documentclass{book}
\usepackage{xltabular}
\makeatletter
\def\LT@caption{%
  \noalign\bgroup
    \@ifnextchar[{\egroup\LT@c@ption\@firstofone}\LT@capti@n}
\makeatother
\begin{document}
\begin{longtable}{c}
\caption{caption}
\endfirsthead
xxx\\xxx
xxx\\xxx
\end{longtable}
\end{document}
hvoss49 commented 1 week ago

We have to revert the patch from David, it has other problems. After that your example will work without modifying \LT@caption

u-fischer commented 1 week ago

what problems? Be aware that if you patch longtable in a way that removes recent additions you probably break the tagging code or hyperref links.

hvoss49 commented 1 week ago

With David's patch it counts with step 2. Table 2, Table 4

\listfiles
\documentclass{article}
\usepackage{xltabular}
\begin{document}

\begin{xltabular}[l]{.7\linewidth}{|c|X|X|}
\caption{A table with a caption\label{tab:A}} \\\hline
1 & \hrulefill 2 \hrulefill & \hrulefill 3 \hrulefill \\
4 & \hrulefill 5 \hrulefill & \hrulefill 6 \hrulefill \\
\hline
\end{xltabular}

\begin{xltabular}[r]{.7\linewidth}{|c|X|X|}
\caption{A table with a caption\label{tab:B}} \\\hline
\hline
1 & \hrulefill 2 \hrulefill & \hrulefill 3 \hrulefill \\
4 & \hrulefill 5 \hrulefill & \hrulefill 6 \hrulefill \\
\hline
\end{xltabular}
\end{document}
u-fischer commented 1 week ago

sure that is my issue. But it works with the original caption command:

\documentclass{article}
\usepackage{xltabular}

\makeatletter
\def\LT@caption{%
  \noalign\bgroup
    \@ifnextchar[{\egroup\LT@c@ption\@firstofone}\LT@capti@n}
\makeatother
\begin{document}

\begin{xltabular}[l]{.7\linewidth}{|c|X|X|}
\caption{A table with a caption\label{tab:A}} \\\hline
1 & \hrulefill 2 \hrulefill & \hrulefill 3 \hrulefill \\
4 & \hrulefill 5 \hrulefill & \hrulefill 6 \hrulefill \\
\hline
\end{xltabular}

\begin{xltabular}[r]{.7\linewidth}{|c|X|X|}
\caption{A table with a caption\label{tab:B}} \\\hline
\hline
1 & \hrulefill 2 \hrulefill & \hrulefill 3 \hrulefill \\
4 & \hrulefill 5 \hrulefill & \hrulefill 6 \hrulefill \\
\hline
\end{xltabular}
\end{document}

image

hvoss49 commented 1 week ago

Uhh, I See. I used the wrong test files. Will discuss it with Rolf ...

hvoss49 commented 1 week ago

We'll upload a new version. We deleted the complete code which fixes the problem with the table counter inside longtable (no caption but counter is still incremented). Then we do not need any of the above patches ...