子图的错误和对齐

子图的错误和对齐

我想在双栏会议论文中并排放置两张图片。LaTeX 代码如下:

\documentclass[conference]{IEEEtran}
% Add the compsoc option for Computer Society conferences.
% *** GRAPHICS RELATED PACKAGES ***
%
\ifCLASSINFOpdf
   \usepackage[pdftex]{graphicx}
  % declare the path(s) where your graphic files are
  % \graphicspath{{../pdf/}{../jpeg/}}
  % and their extensions so you won't have to specify these with
  % every instance of \includegraphics
   \DeclareGraphicsExtensions{.pdf,.jpeg,.png,.eps}
\else
  % or other class option (dvipsone, dvipdf, if not using dvips). graphicx
  % will default to the driver specified in the system graphics.cfg if no
  % driver is specified.
   \usepackage[dvips]{graphicx}
  % declare the path(s) where your graphic files are
  % \graphicspath{{../eps/}}
  % and their extensions so you won't have to specify these with
  % every instance of \includegraphics
   \DeclareGraphicsExtensions{.eps}
\fi

% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}
\usepackage{lscape}
\usepackage{subfigure}

\begin{document}
%
% paper title
% can use linebreaks \\ within to get better formatting as desired
\title{0000}

\author{\IEEEauthorblockN{00000}}

% make the title area
\maketitle


\begin{abstract}
\end{abstract}

\IEEEpeerreviewmaketitle

\section{0000}

\begin{figure}
\centering
\begin{subfig}{.5\textwidth}
  \centering
  \includegraphics[width=.4\linewidth]{pic/interest.png}
  \label{packet:interest}
\end{subfig}
\begin{subfig}{.5\textwidth}
  \centering
  \includegraphics[width=.4\linewidth]{pic/data.png}
  \label{packet:data}
\end{subfig}
\caption{CPI packet structure}
\label{packet}
\end{figure}

\begin{thebibliography}{1}

\end{thebibliography}

\end{document}

我使用了一个.cls文件IEEEtran.cls

www.ctan.org/tex-archive/macros/latex/contrib/IEEEtran/IEEEtran.cls‎

我收到以下错误:

There's no line here to end.
Missing number, treated as zero

结果如下:

enter image description here

除了子图之外还有两个意外.5,这两个子图在底部对齐,但我希望将它们对齐在顶部。

如何修改代码?

答案1

您混合使用了不兼容的语法。使用该subfigure包,您有一个\subfig命令,但没有subfig环境。

但是,调用\begin{subfig}执行\subfig时会产生混淆,因为它不期望将长度作为参数。

该包具有规定长度的环境形式subcaption,但该环境被称为subfigure

这是编译代码。请注意,我加载了仅显示黑色斑点而不是(不可用的)图片的graphicx选项。在图片选项中,我添加了一个语句,以便使它们具有不同的高度;当然,您不需要这个语句。demoheight=

另外回想一下,该论文是采用两栏格式排版的,因此您有两种选择:

  1. 使用figure环境并将宽度表示为\columnwidth

  2. 使用figure*环境并将宽度表示为的分数\textwidth

我使用了第一种形式;该lipsum包只是为了用无意义的文本填充页面。

\documentclass[conference]{IEEEtran}
% Add the compsoc option for Computer Society conferences.
% *** GRAPHICS RELATED PACKAGES ***
%
\usepackage[demo]{graphicx} % demo is just for the example
\usepackage{subcaption}

% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}
\usepackage{lipsum}

\begin{document}
%
% paper title
% can use linebreaks \\ within to get better formatting as desired
\title{0000}

\author{\IEEEauthorblockN{00000}}



% make the title area
\maketitle


\begin{abstract}
\lipsum[1]
\end{abstract}

\IEEEpeerreviewmaketitle

\section{0000}

\lipsum[1-3]

\begin{figure}
\centering
\begin{subfigure}[t]{.5\columnwidth}
  \centering
  \vspace{0pt}
  \includegraphics[width=.4\linewidth,height=3cm]{pic/interest.png}
\end{subfigure}% <--- This is important!!!!
\begin{subfigure}[t]{.5\columnwidth}
  \centering
  \vspace{0pt}
  \includegraphics[width=.4\linewidth,height=4cm]{pic/data.png}
\end{subfigure}
\caption{CPI packet structure}
\label{packet}
\end{figure}

\lipsum

\begin{thebibliography}{1}
\bibitem{a} x
\end{thebibliography}

\end{document}

enter image description here

答案2

这是结果:将图片与双列格式的顶部边框对齐。

 \documentclass[a4paper,12pt,twocolumn]{article}
 \usepackage[inner=0.75in,outer=0.65in,top=0.75in,bottom=0.65in]{geometry}
 \usepackage{lipsum}
 \usepackage{subfigure}
 \usepackage[demo]{graphicx}
 \begin{document}
 \lipsum[1-2]
 \begin{figure}[!hbt]
 \centering
 \begin{subfigure}
 \centering
 \includegraphics[width=.4\columnwidth,height=4cm]{pic/interest.png}
 \label{fig:sub1}
 \end{subfigure}
 \begin{subfigure}
 \centering
 \raisebox{1cm}\includegraphics[width=.4\columnwidth,height=3cm]{pic/data.png}
 \label{fig:sub2}
 \end{subfigure}
 \caption{CPI packet structure}
 \label{packet}
 \end{figure}
 \lipsum[1-10]
 \end{document}

enter image description here

相关内容