假设我有一个名为的自定义环境solution
:
\documentclass[paper = B5]{scrbook}
\usepackage{fontspec}
\usepackage{lipsum}
\setmainfont{Libertinus Serif}
\NewDocumentCommand\sparsetext{m}{{\addfontfeature{LetterSpace = 30}#1}}
\NewDocumentEnvironment{solution}{+b}{%
\par\footnotesize\sparsetext{Solution}. #1%
}{\par}
\begin{document}
\begin{solution}
\lipsum[1]
\end{solution}
\end{document}
如果我插入图片,我就无法将其放在一个段落中:
\documentclass[paper = B5]{scrbook}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{floatflt}
\usepackage{lipsum}
\setmainfont{Libertinus Serif}
\NewDocumentCommand\sparsetext{m}{{\addfontfeature{LetterSpace = 30}#1}}
\NewDocumentEnvironment{solution}{+b}{%
\par\footnotesize\sparsetext{Solution}. #1%
}{\par}
\begin{document}
\newsavebox{\afig}
\begin{lrbox}{\afig}
\begin{tikzpicture}
\draw (0, 0) circle [radius = 1];
\end{tikzpicture}
\end{lrbox}
\begin{solution}%
\begin{floatingfigure}[p]{\wd\afig}%
\noindent\usebox{\afig}%
\end{floatingfigure}%
\lipsum[1]
\end{solution}
\end{document}
我怎样才能将文本保持在一个段落内?
答案1
{floatingfigure}
不能在段落中间使用,而必须在应处于活动状态的段落之前使用。这不能轻易改变,因为floatflt
必须插入一个试验段落来确定图形是否适合当前页面。但由于您的段落从代码内部开始\begin{solution}
,您可以将图形移到其前面:
\documentclass[paper = B5]{scrbook}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{floatflt}
\usepackage{lipsum}
\setmainfont{Libertinus Serif}
\NewDocumentCommand\sparsetext{m}{{\addfontfeature{LetterSpace = 30}#1}}
\NewDocumentEnvironment{solution}{}{%
\par\footnotesize\sparsetext{Solution}.
}{\par}
\begin{document}
\newsavebox{\afig}
\begin{lrbox}{\afig}
\begin{tikzpicture}
\draw (0, 0) circle [radius = 1];
\end{tikzpicture}
\end{lrbox}
\begin{floatingfigure}[p]{\wd\afig}%
\noindent\usebox{\afig}%
\end{floatingfigure}%
\begin{solution}%
\lipsum[1]
\end{solution}
\end{document}