为什么我的子浮点数没有对齐?

为什么我的子浮点数没有对齐?

我将图表和表格并列放在一起:

\documentclass[format=acmsmall, review=false, screen=true]{acmart}

\usepackage{multicol}      % http://ctan.org/pkg/multicols
\usepackage{balance}       % to better equalize the last page
\usepackage{graphicx}      % for EPS, load graphicx instead    
\usepackage{subfig}
\usepackage[export]{adjustbox}

\begin{document}
\begin{figure}
    \centering
    \subfloat[]{\includegraphics[width=0.4\columnwidth, keepaspectratio]{OSM_copy.png}\label{OSM}}
    \subfloat[]
    {
    \resizebox{0.5\columnwidth}{!}{
    \begin{tabular}{|c|c|c|c|}
        \hline \rule[-2ex]{0pt}{5.5ex}  \bf Location Type & \bf Index & \bf Location Type & \bf Index  \\ 
        \hline
        \hline \rule[-1ex]{0pt}{5.5ex}  Bar & \raisebox{-0.1cm}{\includegraphics[scale=0.7]{index_bar.png}} & Taxi stand &  \raisebox{-0.1cm}{\includegraphics[scale=0.5]{index_taxi.png}}\\ 
        \hline \rule[-2ex]{0pt}{5.5ex}  Food court &  \raisebox{-0.3cm}{\includegraphics[scale=0.7]{index_foodcourt.png}} & Hospital &  \raisebox{-0.2cm}{\includegraphics[scale=0.5]{index_hospital.png}} \\ 
        \hline \rule[-2ex]{0pt}{5.5ex}  Library &  \raisebox{-0.2cm}{\includegraphics[scale=0.5]{index_library.png}} & Pharmacy &  \raisebox{-0.2cm}{\includegraphics[scale=0.5]{index_pharmacy.png}} \\ 
        \hline \rule[-2ex]{0pt}{5.5ex}  Fuel station &  \raisebox{-0.2cm}{\includegraphics[scale=0.5]{index_fuel.png}} & Movie theater &  \raisebox{-0.2cm}{\includegraphics[scale=0.5]{index_movie.png}} \\ 
        \hline \rule[-2ex]{0pt}{5.5ex}  Parking &  \raisebox{-0.1cm}{\includegraphics[scale=0.5]{index_parking.png}} & Public telephone &  \raisebox{-0.2cm}{\includegraphics[scale=0.5]{index_phone.png}} \\
        \hline 
    \end{tabular}}
    \label{table2}
    }
    \caption[]{(a) An area in Taipei showing different location types. (b) Some of the location types defined in OSM. }
    \label{fig:location}
\end{figure}

\end{document}

这是我得到的输出:

在此处输入图片描述

为什么它们不出现在同一个“平面”上?我该如何纠正?

以下是上述代码中使用的图像文件的下载链接: https://drive.google.com/open?id=0B54tuvGDke8pTW1rSU9CWEtrYzQ

答案1

默认的垂直对齐方式tabular(除非另有说明)位于中心,而图像的垂直对齐方式位于基线。这些垂直对齐位置可以看作锚点,如果放置在同一条水平线上,它们会彼此对齐。下面是一个快速演示:

在此处输入图片描述

\documentclass{article}

\usepackage[export]{adjustbox}

\begin{document}

x
\includegraphics[height=2\baselineskip]{example-image}
x
\begin{tabular}{c} \hline a \\ b \\ c \\ \hline \end{tabular}
x
\begin{tabular}[t]{c} \hline a \\ b \\ c \\ \hline \end{tabular}
x
\begin{tabular}[b]{c} \hline a \\ b \\ c \\ \hline \end{tabular}
x
\adjustbox{valign=t}{\begin{tabular}[b]{c} \hline a \\ b \\ c \\ \hline \end{tabular}}
x
\adjustbox{valign=T}{\begin{tabular}[b]{c} \hline a \\ b \\ c \\ \hline \end{tabular}}
x
\adjustbox{valign=b}{\begin{tabular}[b]{c} \hline a \\ b \\ c \\ \hline \end{tabular}}
x
\adjustbox{valign=B}{\begin{tabular}[b]{c} \hline a \\ b \\ c \\ \hline \end{tabular}}
x

\bigskip\bigskip

x
\includegraphics[height=2\baselineskip,valign=c]{example-image}
x
\begin{tabular}{c} a \\ b \\ c \end{tabular}
x

\end{document}

考虑到上述情况,您可以将图像对齐到其垂直中心(而不是基线),或者将其对齐tabular到其B基线(而不是其垂直中心)以对齐两个图像。

但是,您仍然有两个高度不同的物体,这可能会令人不快。我采用了您的代码并添加了一些功能,包括valign对图像和进行修改tabular,以及使用booktabs。请注意图例中每幅图像都使用了一致的height(子图 (b));这为表格各行提供了一致性,而无需猜测合适的scale

在此处输入图片描述

\documentclass[format=acmsmall, review=false, screen=true]{acmart}

\usepackage{subfig,booktabs,makecell}
\usepackage[export]{adjustbox}

\begin{document}
\begin{figure}
  \centering
  \subfloat[]
    {\includegraphics[width=0.4\columnwidth]{OSM_copy.png}}\quad
  \subfloat[]
    {\adjustbox{width=0.5\columnwidth,valign=B,raise=2\baselineskip}{%
      \renewcommand{\arraystretch}{1.5}%
      \begin{tabular}{ *{4}{c} }
        \toprule
        \bfseries \makecell[b]{Location \\ type} & \bfseries Index & 
          \bfseries \makecell[b]{Location \\ type} & \bfseries Index \\
        \midrule
        Bar          & \includegraphics[height=12pt,valign=c]{index_bar.png}       & 
          Taxi stand       & \includegraphics[height=12pt,valign=c]{index_taxi.png}     \\
        Food court   & \includegraphics[height=12pt,valign=c]{index_foodcourt.png} & 
          Hospital         & \includegraphics[height=12pt,valign=c]{index_hospital.png} \\
        Library      & \includegraphics[height=12pt,valign=c]{index_library.png}   & 
          Pharmacy         & \includegraphics[height=12pt,valign=c]{index_pharmacy.png} \\
        Fuel station & \includegraphics[height=12pt,valign=c]{index_fuel.png}      & 
          Movie theater    & \includegraphics[height=12pt,valign=c]{index_movie.png}    \\
        Parking      & \includegraphics[height=12pt,valign=c]{index_parking.png}   & 
          Public telephone & \includegraphics[height=12pt,valign=c]{index_phone.png}    \\
        \bottomrule
      \end{tabular}}
    }
  \caption{%
    (a) An area in Taipei showing different location types.
    (b) Some of the location types defined in OSM.}
\end{figure}

\end{document}

答案2

tabularx这是一个使用环境而不是的解决方案tabular。它还使用包中的一些宏booktabs来为表格材料提供更开放的空间。最后,它使用了subcaption包。(我使用了“demo”选项,因为我无法访问各种图像文件;在实际代码中省略“demo”选项。)

在此处输入图片描述

\documentclass[format=acmsmall, review=false, screen=true, 
               demo]{acmart} % remove 'demo' option in real document

\usepackage{multicol} % Q: Do you really need this package? 
\usepackage{balance}   
\usepackage{graphicx}
\usepackage{subcaption} % Load 'subcaption' instead of 'subfig'
\usepackage{tabularx,booktabs,ragged2e}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\newcolumntype{C}{>{\Centering\arraybackslash}X}

\begin{document}

\begin{figure}
\begin{subfigure}[t]{0.42\textwidth}
\includegraphics[width=\linewidth, keepaspectratio]{OSM_copy.png}
\caption{} \label{OSM}
\end{subfigure}%
\hfill% Maximize the distance between the two subfigure environments
\begin{subfigure}[t]{0.55\textwidth}
\begin{tabularx}{\linewidth}{@{}Cm{10mm}Cm{10mm}@{}}
Location Type & Index & Location Type & Index  \\ 
\midrule
Bar              & \includegraphics[width=\linewidth,height=\linewidth]{index_bar.png} & 
Taxi stand       & \includegraphics[width=\linewidth,height=\linewidth]{index_taxi.png}\\ 
\addlinespace
Food court       & \includegraphics[width=\linewidth,height=\linewidth]{index_foodcourt.png} & 
Hospital         & \includegraphics[width=\linewidth,height=\linewidth]{index_hospital.png} \\ 
\addlinespace
Library          & \includegraphics[width=\linewidth,height=\linewidth]{index_library.png} & 
Pharmacy         & \includegraphics[width=\linewidth,height=\linewidth]{index_pharmacy.png} \\ 
\addlinespace
Fuel station     & \includegraphics[width=\linewidth,height=\linewidth]{index_fuel.png} & 
Movie theater    & \includegraphics[width=\linewidth,height=\linewidth]{index_movie.png} \\ 
\addlinespace
Parking          & \includegraphics[width=\linewidth,height=\linewidth]{index_parking.png} & 
Public telephone & \includegraphics[width=\linewidth,height=\linewidth]{index_phone.png} \\
\end{tabularx}
\caption{} \label{table2}
\end{subfigure}
\caption[]{(a) An area in Taipei showing different location types. 
           (b) Some of the location types defined in OSM. }
\label{fig:location}
\end{figure}

\end{document}

相关内容