如何将图片放在页面中间或所需位置

如何将图片放在页面中间或所需位置

我怎样才能将横跨两列文本的图形放在页面的中间或所需位置(而不是顶部或底部)。

\documentclass{IEEEtran}

\begin{document}

\begin{figure*}[h]
\includegraphics{image-file}
\end{figure*}

\end{document}

答案1

为了说明 Barbara Beeton 的观点。请注意,插入\vspace不必位于精确的位置,但必须位于换行前的最后一行的某个位置。

\documentclass{IEEEtran}
\usepackage{graphicx}
\usepackage{lipsum}

\newlength{\tempheight}

\begin{document}
\lipsum[1]

\begin{figure}[h]
\sbox0{% get height
\begin{minipage}{\textwidth}
\centering
\includegraphics{example-image}
\caption{test}
\end{minipage}}%
\global\tempheight=\dimexpr \ht0+\dp0+2\intextsep\relax
\rlap{\usebox0}
\end{figure}

\lipsum[2-3]

Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel
justo vitae lacus tincidunt ultrices. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. In hac habitasse platea dictumst.
Integer tempus convallis augue. Etiam facilisis. Nunc elementum
fermentum wisi. Aenean placerat. Ut imperdiet, enim sed
gravida sollicitudin, felis odio placerat quam, ac pulvinar elit
purus eget enim. 
\vspace{\tempheight}% ***** insert blank space here *****
Nunc vitae tortor.  Proin tempus nibh sit amet
nisl. Vivamus quis tortor vitae risus porta vehicula.

\lipsum[5-6]

\end{document}

答案2

该解决方案基于短页宏。限制:(1)文本参数必须从上一页开始。(2)文本参数中不能有浮点数。(3)文本参数必须由一个或多个完整段落组成。

请注意,在开始阅读图表下方的列*之前,请先阅读图表上方的两列*。

\documentclass{IEEEtran}
\usepackage{graphicx}
\usepackage{afterpage}
\usepackage{multicol}
\usepackage{lipsum}

\newsavebox{\shortpagebox}
\newsavebox{\shortpagefigure}

\makeatletter
\newcommand{\shortpage}[2]% #1 = text, #2 = figure*
{\par
  \setbox\shortpagebox=\vbox{\strut #1\par}% cram text together
  \global\setbox\shortpagefigure=\vbox{\hsize=\textwidth
    \def\@captype{figure}%
    #2}% store figure
  \afterpage{\twocolumn[%
    \begin{multicols}{2}
    \unvbox\AP@partial
    \end{multicols}\par
    \vskip\intextsep
    \box\shortpagefigure
    \vskip\dbltextfloatsep]}
  \unvbox\shortpagebox
\par}
\makeatother

\begin{document}
\lipsum[1-10]\strut
%\hrule% locate start of short page

\shortpage{\lipsum[11-12]}%
{\centering
  \includegraphics{example-image}
  \caption{test}}
\lipsum[12-16]

\end{document}

相关内容