![当图片位于环境 \begin 之后时,如何包装图片?](https://linux22.com/image/398028/%E5%BD%93%E5%9B%BE%E7%89%87%E4%BD%8D%E4%BA%8E%E7%8E%AF%E5%A2%83%20%5Cbegin%20%E4%B9%8B%E5%90%8E%E6%97%B6%EF%BC%8C%E5%A6%82%E4%BD%95%E5%8C%85%E8%A3%85%E5%9B%BE%E7%89%87%EF%BC%9F.png)
我正在尝试在环境中包装图片。我看到那里的人们insbox.tex
在不同的答案中推荐使用。下面的代码一切都很好。但是,当图片被引入后,\begin{group}
它根本不起作用。
编辑:我不\leavevmode
这么认为。
看看我的 MWE:
\documentclass{book}
\usepackage{amsthm}
\usepackage{lipsum}
\newtheorem{thm}{Theorem}
\usepackage{graphicx}
\usepackage[font=footnotesize]{caption}
\input{insbox.tex}
\usepackage{threeparttable}
\usepackage{xargs}
\newcommand\insertpictureR[3][5]{
\InsertBoxR{0}{\begin{threeparttable}\begin{tabular}{c@{}}\includegraphics[width=#3\textwidth]{#2}\end{tabular}\captionof{figure}{}\end{threeparttable}}[#1]%
}
\newcommand\insertpictureL[3][5]{
\InsertBoxL{0}{\begin{threeparttable}\begin{tabular}{c@{}}\includegraphics[width=#3\textwidth]{#2}\end{tabular}\captionof{figure}{}\end{threeparttable}}[#1]%
}
\begin{document}
\begin{thm}
\insertpictureR{example-image-a}{0.2}
\lipsum[1]
\end{thm}
\begin{proof}
\insertpictureL{example-image-a}{0.2}
\lipsum[1]
\end{proof}
\end{document}
答案1
您缺少了\leavevmode
和一些其他好东西。请注意,您的宏似乎系统地要求使用可选参数(也许没有正确考虑标题高度?)。
\documentclass{book}
\usepackage{amsthm}
\usepackage{lipsum}
\newtheorem{thm}{Theorem}
\usepackage{graphicx}
\usepackage[font=footnotesize]{caption}
\input{insbox.tex}
\usepackage{threeparttable}
\usepackage{xargs}
\newcommand\insertpictureR[3][5]{
\InsertBoxR{0}{\begin{threeparttable}\begin{tabular}{c@{}}\includegraphics[width=#3\textwidth]{#2}\end{tabular}\captionof{figure}{}\end{threeparttable}}[#1]%
}
\newcommand\insertpictureL[3][5]{
\InsertBoxL{0}{\begin{threeparttable}\begin{tabular}{c@{}}\includegraphics[width=#3\textwidth]{#2}\end{tabular}\captionof{figure}{}\end{threeparttable}}[#1]%
}
\begin{document}
\begin{thm} \leavevmode
\insertpictureR[3]{example-image-a}{0.2}\noindent
\lipsum[1]
\end{thm}%
\begin{proof}
\leavevmode\insertpictureL[3]{example-image-a}{0.2}\noindent
\lipsum[1]
\end{proof}
\end{document}