将 endfloat 与将 appendix-section 添加到标题相结合

将 endfloat 与将 appendix-section 添加到标题相结合

我在尝试着

  • 在文章末尾、附录之前处理正文中的图表endfloat(以下这次讨论
  • 在附录中,将章节标识符添加到图表和表格标题中,例如,Table A1使用例如\renewcommand{\thetable}{\thesection\arabic{table}}(以下这次讨论

虽然每个“功能”都独立工作,但当在下面的 MWE 中注释掉相关行时,这两个功能一起会导致编译错误。我怀疑这会endfloat扰乱整个文档中的标题相关环境。

我怎样才能解决这个问题?

请参阅下面的 MWE(我使用 xelatex 编译)

\documentclass[11pt,a4paper]{article}

\usepackage[
    a4paper,
    left=1in,
    right=1in,
    top=1.5in,
    bottom=1.5in
]{geometry}                              % DIN A4 margins
\usepackage[toc,page,titletoc,title]{appendix}     % appendix
\usepackage[font=large,labelfont=bf]{caption}      % format captions
\usepackage{subcaption}                            % create subfigures
\setlength{\abovecaptionskip}{8pt}                 % caption settings
\usepackage{adjustbox}                             % scale tables and figures to page size
\usepackage{graphicx}                              % figures
\usepackage[figuresfirst,nomarkers,nolists]{endfloat}      % put tables and figures at end

\begin{document}

% -------------------- article ----------------------- %

Some text.

\begin{table}
    \centering
    \caption{Title}
    \caption*{Some description}
    \label{tab:table-1}
    \begin{tabular}{ c c c }
     cell1 & cell2 & cell3 \\ 
     cell4 & cell5 & cell6 \\  
     cell7 & cell8 & cell9    
    \end{tabular}
\end{table}

\newpage

Some text.

% -------------------- tables and figures ----------------------- %
% process delayed floats here, i.e., at end of body but before the appendix
\clearpage
\processdelayedfloats

% -------------------- appendix ----------------------- %
\clearpage

\renewcommand\appendixname{Appendix}

\appendix

% restart counter within each section
\counterwithin{figure}{section}
\counterwithin{table}{section}

% set names
\renewcommand{\thefigure}{\thesection\arabic{figure}}
\renewcommand{\thetable}{\thesection\arabic{table}}

\begin{appendices}   
    \section{Something with Tables}

    \begin{table}
        \centering
        \caption{Title}
        \caption*{Some description}
        \label{tab:appendix-table-1}
        \begin{tabular}{ c c c }
         cell1 & cell2 & cell3 \\ 
         cell4 & cell5 & cell6 \\  
         cell7 & cell8 & cell9    
        \end{tabular}
    \end{table}

\end{appendices}

\end{document}

答案1

看起来endfloat确实应该受到指责这个帖子

解决方案是恢复所有环境的旧定义endfloat并重新定义。

改变后的 MWE 现在可以按预期进行编译。

\documentclass[11pt,a4paper]{article}

\usepackage[
    a4paper,
    left=1in,
    right=1in,
    top=1.5in,
    bottom=1.5in
]{geometry}                              % DIN A4 margins
\usepackage[toc,page,titletoc,title]{appendix}     % appendix
\usepackage[font=large,labelfont=bf]{caption}      % format captions
\usepackage{subcaption}                            % create subfigures
\setlength{\abovecaptionskip}{8pt}                 % caption settings
\usepackage{adjustbox}                             % scale tables and figures to page size
\usepackage{graphicx}                              % figures
\usepackage[figuresfirst,nomarkers,nolists]{endfloat}      % put tables and figures at end

\begin{document}

% -------------------- article ----------------------- %

Some text.

\begin{table}
    \centering
    \caption{Title}
    \caption*{Some description}
    \label{tab:table-1}
    \begin{tabular}{ c c c }
     cell1 & cell2 & cell3 \\ 
     cell4 & cell5 & cell6 \\  
     cell7 & cell8 & cell9    
    \end{tabular}
\end{table}

\newpage

Some text.

% -------------------- tables and figures ----------------------- %
% process delayed floats here, i.e., at end of body but before the appendix
\clearpage
\processdelayedfloats
% restore the old definitions of all environments endfloat has re-defined
% this is necessary to change captions in the appendix
\csname efloat@restorefloats\endcsname   % <---------------------------- added

% -------------------- appendix ----------------------- %
\clearpage

\renewcommand\appendixname{Appendix}

\appendix

% restart counter within each section
\counterwithin{figure}{section}
\counterwithin{table}{section}

% set names
\renewcommand{\thefigure}{\thesection\arabic{figure}}
\renewcommand{\thetable}{\thesection\arabic{table}}

\begin{appendices}   
    \section{Something with Tables}

    \begin{table}
        \centering
        \caption{Title}
        \caption*{Some description}
        \label{tab:appendix-table-1}
        \begin{tabular}{ c c c }
         cell1 & cell2 & cell3 \\ 
         cell4 & cell5 & cell6 \\  
         cell7 & cell8 & cell9    
        \end{tabular}
    \end{table}

\end{appendices}

\end{document}

相关内容