无法手动控制 endfloat 的 ToC 和 header 行为

无法手动控制 endfloat 的 ToC 和 header 行为

在我的论文中,我希望

  • 每章末尾的每个图表都单独放在一页上(方便使用endfloat
  • 每章的第一个图开始其自己的章节,并进入目录,但实际文档中没有出现章节标题。
  • 与上一点相同,但带有表格
  • 图表部分的页眉反映了变化

我可以用以下语句来结束文档\processdelayedfloats

  • 标题正确地随表格部分更改,但表格仍保留在标题中的图形部分中
  • 目录中既没有表格,也没有图形。

或者我取消注释最后几行然后:

  • 表格标题继续进入新部分 1 页,然后更改为新部分
  • 目录已更新,但图表和表格的页码都是第一个非浮动页。
  • hyperref将图表和表格目录条目链接到既不列出的页面也不链接到第一个表格/图表。

虽然这个软件包的理念很棒endfloat,但我认为它的实现效果不佳。如果能帮助解决这个问题(以及理解这个软件包的工作原理),我将不胜感激。

梅威瑟:

\documentclass[oneside]{memoir}

\usepackage[nolists,nomarkers,noheads,tablesfirst]{endfloat}
%%%%%%%%%%%%% stop endfloat from marking both headers %%%%%%%%%%%%% 
    \usepackage{etoolbox}
        \makeatletter
        \patchcmd{\efloat@process}{\markboth}{\@gobbletwo}{}{}
        \makeatother
    \AtBeginTables{\addcontentsline{toc}{section}{Tables}\markright{Tables}}
    \AtBeginFigures{\markright{Figures} \addcontentsline{toc}{section}{Figures}}

\usepackage{lipsum}

\makepagestyle{mainMatter}
\makeoddfoot{mainMatter}{}{\thepage}{}
\makeoddhead{mainMatter}{\leftmark}{}{\rightmark}
\makeheadrule{mainMatter}{\linewidth}{\normalrulethickness}
\makepsmarks{mainMatter}{%
    \nouppercaseheads
    \createmark{section}{right}{nonumber}{}{. \ }
    \createmark{chapter}{left}{shownumber}{Chapter }{: \ }}

\usepackage{hyperref}

\begin{document}
\tableofcontents*
\pagestyle{mainMatter}
\chapter{My Chapter}
\section{My Section}
\lipsum[1]
\begin{figure}
\centering
\fbox{{\HUGE a figure}}
\caption{A Figure placed here}\label{fig:a fig}
\end{figure}
\lipsum[1]
\begin{table}
  \centering
  \caption{Cool table}
    \begin{tabular}{lc}
   A  & 100 \\
   B & 41 \\
   C  & 17 \\
   X?!  & 0 \\
    \end{tabular}
  \label{tab:my table 1}
\end{table}

\begin{figure}
\centering
\fbox{{\HUGE another figure}}
\caption{A Figure placed here}\label{fig:a fig 2}
\end{figure}

\begin{table}
  \centering
  \caption{boring table}
    \begin{tabular}{c|c}
A & B \\
    \end{tabular}
  \label{tab:my table 2}
\end{table}
\lipsum[1]
\processdelayedfloats
\section{Frustrated}
Note that if you uncomment the line below, suddenly the ToC gets updated (incorrectly) and the next page has a new header.
\lipsum[1-8]

\end{document}

答案1

我不知道自己在做什么,但我明白了!关键是:

  • 禁用标记两者(与原始 MWE 一样)
  • 启用该heads选项以便endfloat尝试加载\section*命令...
  • 但首先用以下\section*命令替换endfloat.sty\phantomsection\addcontentsline{toc}{section}{\@nameuse{#2section}}\markright

    • hyperref我在 ToC 中遇到的问题已通过以下方式解决:\phantomsection
    • 右标题被替换为\@nameuse{#2section,根据浮动,其为图形或表格。如果没有该heads选项,endfloat将跳过此部分。
  • \AtBeginTables每个图形和表格都位于页面中央,并且由于不断重新定义默认位置(感谢、\AtBeginFigures\efloatseparator),浮动元素前后没有空白页

  • 最后一个浮动将出现在任何其他文本之前,因为\processdelayedfloats现在包含一个\FloatBarrier

    • 包含\FloatBlock意味着此修复需要该类memoir。或者,placeins可以使用包来替代\FloatBarrier\FloatBlock(我假设)将获得相同的结果。

这是新的 MWE,它正好能满足我的要求。希望在这里回答自己的问题没问题。

编辑虽然此修复在我的 MWE 中有效,但它在我的实际文档中不起作用。可能是因为某些标题太长,加载了其他包,或者我用它include来加载章节。无论出于什么原因,我仍然遇到这个问题。

\documentclass[oneside]{memoir}

\usepackage[nolists,heads,nomarkers,tablesfirst]{endfloat}
    \usepackage{etoolbox}
        \makeatletter
        \patchcmd{\efloat@process}{\markboth}{\@gobbletwo}{}{}
        \patchcmd{\efloat@process}{\section*}{\phantomsection\addcontentsline{toc}{section}{\@nameuse{#2section}}\markright}{}{}
        \patchcmd{\processdelayedfloats}{\processotherdelayedfloats}{\processotherdelayedfloats\FloatBlock}{}{}
        \makeatother
    \AtBeginTables{\setfloatlocations{table}{h}\null\vfill}
%
    \AtBeginFigures{\setfloatlocations{figure}{h}\null\vfill}

    \AtBeginDelayedFloats{}
    \renewcommand{\efloatseparator}{\vfill\setfloatlocations{table}{p}\setfloatlocations{figure}{p}}


\usepackage{lipsum}

\makepagestyle{mainMatter}
\makeoddfoot{mainMatter}{}{\thepage}{}
\makeoddhead{mainMatter}{\leftmark}{}{\rightmark}
\makeheadrule{mainMatter}{\linewidth}{\normalrulethickness}
\makepsmarks{mainMatter}{%
    \nouppercaseheads
    \createmark{section}{right}{nonumber}{}{. \ }
    \createmark{chapter}{left}{shownumber}{Chapter }{: \ }}

\usepackage{hyperref}




\begin{document}
\tableofcontents*
\pagestyle{mainMatter}
\chapter{My Chapter}
\section{My Section}
\lipsum[1]

\begin{figure}
\centering
\fbox{{\HUGE a figure}}
\caption{A Figure placed here}\label{fig:a fig}
\end{figure}
\lipsum[1]

\begin{table}
  \centering
  \caption{Cool table}
    \begin{tabular}{lc}
   A  & 100 \\
   B & 41 \\
   C  & 17 \\
   X?!  & 0 \\
    \end{tabular}
  \label{tab:my table 1}
\end{table}

\begin{figure}
\centering
\fbox{{\HUGE another figure}}
\caption{A Figure placed here}\label{fig:a fig 2}
\end{figure}

\begin{table}
  \centering
  \caption{boring table}
    \begin{tabular}{c|c}
A & B \\
    \end{tabular}
  \label{tab:my table 2}
\end{table}



\lipsum[1]
\processdelayedfloats


\section{HURRAY!}
I deserve a beer.
    \lipsum[1-8]

\end{document}

相关内容