我们用\minisec{my fancy heading}
它来生成章节或节内的多个中间标题。但这些小标题内通常也有浮动,有时会浮出标题。
对于部分(到段落),我们使用以下代码来防止对象在环境之外浮动。我的第一个想法是重复使用此代码,\minisec
但它不起作用。我不确定这是否\minisec
是一个真正的类似部分的环境,还是只是一个好看的中间标题。
有什么办法可以实现这个功能吗?对我来说,重新定义\minisec
是最好的解决方案。
提前谢谢!
\documentclass{scrreprt}
\usepackage{tabularx}
\makeatletter
\AtBeginDocument{%
\expandafter\renewcommand\expandafter\minisec\expandafter{%
\expandafter\@fb@secFB\minisec
}%
}
\makeatother
\begin{document}
\chapter{My Section}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\minisec{Minisec 1}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr.
\begin{table}[htpb]
\caption{My table}
\begin{tabularx}{\columnwidth}{XXl}
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum
\end{tabularx}
\end{table}
\minisec{Minisec 2}
Text text Text text Text text
\end{document}
答案1
防止浮动元素超出文档区域的建议解决方案是使用包裹placeins
:
\documentclass{scrreprt}
\usepackage{tabularx}
\usepackage{placeins}
\usepackage{mwe}
\begin{document}
\chapter{My Section}
\lipsum[1]
\minisec{Minisec 1}
\lipsum[1-2]
\begin{table}[htpb]
\caption{My table}
\begin{tabularx}{\columnwidth}{XXl}
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum
\end{tabularx}
\end{table}
\FloatBarrier
\minisec{Minisec 2}
Text text Text text Text text
\end{document}
您可以使用xpatch
补丁\minisec
总是以以下内容开头\FloatBarrier
:
\documentclass{scrreprt}
\usepackage{tabularx}
\usepackage{placeins}
\usepackage{xpatch}
\xpretocmd{\minisec}{\FloatBarrier}{}{}
\usepackage{mwe}
\begin{document}
\chapter{My Section}
\lipsum[1]
\minisec{Minisec 1}
\lipsum[1-2]
\begin{table}[htpb]
\caption{My table}
\begin{tabularx}{\columnwidth}{XXl}
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum
\end{tabularx}
\end{table}
\minisec{Minisec 2}
Text text Text text Text text
\end{document}
如果您想使用内部placeins
命令\@fb@secFB
,您必须在修补之前使用以下命令加载placeins
选项:section
\minisec
\AtBeginDocument
\documentclass{scrreprt}
\usepackage{tabularx}
\usepackage[section]{placeins}
\usepackage{xpatch}
\makeatletter
\AtBeginDocument{%
\xpretocmd{\minisec}{\@fb@secFB}{}{}%
}
\makeatother
\usepackage{mwe}
\begin{document}
\chapter{My Section}
\lipsum[1]
\minisec{Minisec 1}
\lipsum[1-2]
\begin{table}[htpb]
\caption{My table}
\begin{tabularx}{\columnwidth}{XXl}
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum\\
Lorem ipsum&Lorem ipsum dolor sit amet&Lorem ipsum
\end{tabularx}
\end{table}
\minisec{Minisec 2}
Text text Text text Text text
\end{document}
两个示例的结果都是: