考虑这个简单的代码。
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage{tikz}
\begin{document}
\begin{multicols}{2}
\lipsum[1]
\begin{figure}
\centering
\begin{tikzpicture}
\draw circle (1);
\end{tikzpicture}
\caption{Figure in two column}
\end{figure}
\lipsum[2]
\end{multicols}
\end{document}
此代码应该显示一个圆圈,但不知何故却没有显示。
但如果我们注释掉\begin{multicols}{2}
和\end{multicols}
,就会出现圆圈。
如何解决这个问题?
答案1
使用\InsertBoxC
纯 TeX 宏包中的命令和\captionof{figure}{...}
,您可以在文本的任何位置插入列宽的图形:当前行将终止,然后插入图形,最后文本将在图形的下一行恢复:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{caption}
\input{insbox.tex}
\begin{document}
\begin{multicols}{2}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
\InsertBoxC{%
\parbox[b][1.1\height]{\columnwidth}{%
\centering \begin{tikzpicture}
\draw circle (1);
\end{tikzpicture}
\captionof{figure}{Figure in two column}
}}%
Mauris ut leo. Cras viverra metus rhoncussem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat.
Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.
\lipsum[2]
\end{multicols}
\end{document}