latex: 在article文档环境(multicols)中, 使用begin{figure}无法显示的问题

来源:互联网 发布:域名注册软件 编辑:程序博客网 时间:2024/05/28 05:15

参考:Image not showing up when using figure environment,multicols宏包插入图片丢失,怎么办?

问题描述:在article环境下,使用begin{figure}无法显示图片,例子如下:

\documentclass[]{article}\usepackage{multicol} % Used for the two-column layout of the document\usepackage{amsmath}\usepackage{graphicx}\graphicspath{ {pics/} }\title{\vspace{-15mm}\fontsize{24pt}{10pt}\selectfont\textbf{Lorem ipsum}} % Article title\begin{document}\maketitle % Insert title\begin{multicols}{2} %%This does not show up\begin{figure}[h]    \includegraphics[width=.4\textwidth]{generalPolya}\end{figure}%This shows up.\begin{center}        \includegraphics[width=.5\textwidth]{chair}\end{center}\end{multicols}\end{document}

问题分析:通过测试,发现\begin{figure}并不能显示,因为在multicols环境中不能使用figure环境,log中会有warning,故存在问题。

Package multicol Warning: Floats and marginpars not allowed inside `multicols' environment!.

解决方法:
方案一、参见ctex-faQ,59个问题。摘录如下:
如果你使用的是LATEX 标准文档类的twocolumn 模式,那么使用figure 和table 环境可以产生单列的
浮动图形或者表格,而使用figure* 和table* 环境则可以产生通栏的浮动图形或者表格。
如果你使用的是multicol 宏包提供的multicols 环境,那么就有一点小问题了。figure 和table 在这种方式下无法正常工作,会导致图形或者表格丢失。但是, figure* 和table* 仍然可以正常工作,产生通栏的浮动图形或者表格,就像在标准文档类的twocolumn 模式下一样。
要在multicols 环境中使用单栏的图形或者表格,可以使用float 宏包提供的[H] 位置选项。例如

\begin{figure}[H]
...
\caption{...}
\end{figure}

但是要注意的是,这种方式产生的对象是不能“浮动”的,也就是说位置是固定的。因此,有时候你必须仔细调整它的位置,以免造成分栏的底部参差不齐。

方案二、在双栏环境下,我们可以不使用figure。可以直接插入图片,居中的话可以用center环境。若是想使用caption和label,导言区加入代码:

\makeatletter\def\@captype{figure}\makeatother\caption{???}\label{xxx}

这样会让图和表格的标题都以figure ,若是table也正常的话。每次使用前修改为\makeatletter
\def\@captype{table}
\makeatother
或者重新定义为:
\makeatletter
\newcommand\figurecaption{\def\@captype{figure}\caption}
\newcommand\tablecaption{\def\@captype{table}\caption}
\makeatother
然后用\figurecaption{XXX}和\tablecaption{XXX}来加标题吧!

方案三、定义新的环境来使用。

\makeatletter\newenvironment{tablehere}  {\def\@captype{table}}  {}\newenvironment{figurehere}  {\def\@captype{figure}}  {}\makeatother

我们直接使用 figurehere 和 tablehere环境就可以了。

1 0
原创粉丝点击