图形居中问题

图形居中问题

我有以下代码:

\begin{figure}[h]
  \begin{subfigure}{0.3\linewidth}
  \centering
     \includegraphics[width=\textwidth, height=4 cm]{boat_gray_256.png}
      \centering
          \caption*{Source: Public-Domain Test Images for Homeworks and Projects \cite{data_bb}} 
         \caption{Boat Image}   
  \label{fig:4_2_1}
   \centering
      \end{subfigure}
         \begin{subfigure}{0.3\linewidth}
                 \centering
 \includegraphics[width=\textwidth, height=4cm]{cameraman_gray_256.png}
  \centering  
  \caption*{Source: Image Databases, Standard   \\ Test Images \cite{data_lwpcmphlwj}}
  \caption{Cameraman Image}
       \label{fig:4_2_2}
  \centering  
   \end{subfigure}
   \newline
        \begin{subfigure}{0.3\linewidth}          
             \centering
 \includegraphics[width=\textwidth, height=4 cm]{lena_gray_256.png}
  \centering   
    \caption*{Source: Image Databases, Standard Test Images \cite{data_lwpcmphlwj}}
       \caption{Lena Image}
        \label{fig:4_2_3}
  \centering

    \end{subfigure}
    \newline
          %\centering                                        
\begin{subfigure}{0.3\linewidth}
  \centering
  \includegraphics[width=\textwidth, height=4cm]{jetplane_gray_256.png}
  \centering  
  \caption*{Source: Image Databases, Standard   \\ Test Images \cite{data_lwpcmphlwj}}
  \caption{Jet Plane Image}
      \label{fig:4_2_4}
  \centering  
   \end{subfigure}
  \begin{subfigure}{0.3\linewidth}
        \centering
  \includegraphics[width=\textwidth, height=4cm]{mri_gray_256.jpg} 
  \centering
  \caption*{Source: Northern Arizona University, Gray Scale Images \cite{data_mri}}
  \caption{MRI Image}
      \label{fig:4_2_5}
  \centering  
   \end{subfigure}
 \caption{Used Images}  
 \label{fig:datasetimages}
    \end{figure} 

问题是 3. 图像 Lena 不在中心,它与船和喷气式飞机垂直成一线。如何将 lena 置于中心?

答案1

也许你对下面的例子就满意了:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}

\begin{figure}[h]
\centering
  \begin{subfigure}[t]{0.3\linewidth}
    \includegraphics[width=\textwidth, height=4 cm]{example-image}
    \caption*{Source: Public-Domain Test Images for Homeworks and Projects \cite{data_bb}} 
    \caption{Boat Image}   
    \label{fig:4_2_1}
  \end{subfigure}\quad
  \begin{subfigure}[t]{0.3\linewidth}
    \includegraphics[width=\textwidth, height=4cm]{example-image} 
    \caption*{Source: Image Databases, Standard  Test Images \cite{data_lwpcmphlwj}}
    \caption{Cameraman Image}
    \label{fig:4_2_2} 
  \end{subfigure}

  \begin{subfigure}[t]{0.3\linewidth}          
    \includegraphics[width=\textwidth, height=4 cm]{example-image}   
    \caption*{Source: Image Databases, Standard Test Images \cite{data_lwpcmphlwj}}
    \caption{Lena Image}
     \label{fig:4_2_3}
  \end{subfigure}

  \begin{subfigure}[t]{0.3\linewidth}
    \includegraphics[width=\textwidth, height=4cm]{example-image} 
    \caption*{Source: Image Databases, Standard   Test Images \cite{data_lwpcmphlwj}}
    \caption{Jet Plane Image}
    \label{fig:4_2_4} 
  \end{subfigure}\quad
  \begin{subfigure}[t]{0.3\linewidth}
    \includegraphics[width=\textwidth, height=4cm]{example-image} 
    \caption*{Source: Northern Arizona University, Gray Scale Images \cite{data_mri}}
    \caption{MRI Image}
    \label{fig:4_2_5}
    \end{subfigure}
\caption{Used Images}  
\label{fig:datasetimages}
\end{figure} 

\end{document}

在此处输入图片描述

与您的原始代码相比,我删除了所有多余的\centering命令。环境开头的其中一个命令figure就足以实现上面显示的布局。为了将图像 c 放在单独的行中,我在代码中在相应的子图环境之前和之后使用了空行。为了在图像 a/b 和 d/e 之间分别获得一些水平空间,我\quad在相应的子图环境之间添加了空间。

答案2

看看您是否喜欢以下解决方案:

编辑: 按照建议米科在他的评论中,我在带有图像的行之间添加了垂直空间:

在此处输入图片描述 - 添加\centeringbegin{figure} - 删除了里面的所有\centering内容subfigure,它们是多余的 - 使用\caption*{...}替换为copyrightbox选项r,将版权材料(图像来源)放在图像的右侧

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage{copyrightbox}

\begin{document}
    \begin{figure}[h]
    \centering
\begin{subfigure}{0.3\linewidth}
\copyrightbox[r]%
    {\includegraphics[width=\textwidth,height=4 cm]{boat_gray_256.png}}
    {Source: Public-Domain Test Images for Homeworks and Projects \cite{data_bb}}%
    \caption{Boat Image}
  \label{fig:4_2_1}
  \end{subfigure}\hfil
    \begin{subfigure}{0.3\linewidth}
    \copyrightbox[r]%
    {\includegraphics[width=\linewidth,height=4cm]{cameraman_gray_256.png}}
    {Source: Image Databases, Standard Test Images \cite{data_lwpcmphlwj}}%
    \caption{Cameraman Image}
       \label{fig:4_2_2}
   \end{subfigure}\\[2ex]
%       
\begin{subfigure}{0.3\linewidth}
\copyrightbox[r]%
    {\includegraphics[width=\linewidth,height=4 cm]{lena_gray_256.png}}
    {Source: Image Databases, Standard Test Images \cite{data_lwpcmphlwj}}%
       \caption{Lena Image}
        \label{fig:4_2_3}
\end{subfigure}\\[2ex]
%       
\begin{subfigure}{0.3\linewidth}
\copyrightbox[r]%
    {\includegraphics[width=\linewidth,height=4cm]{jetplane_gray_256.png}}
    {Source: Image Databases, Standard Test Images \cite{data_lwpcmphlwj}}%
\caption{Jet Plane Image}
\label{fig:4_2_4}
\end{subfigure}
    \begin{subfigure}{0.3\linewidth}
    \copyrightbox[r]%
    {\includegraphics[width=\linewidth,height=4cm]{mri_gray_256.jpg}}
    {Source: Northern Arizona University, Gray Scale Images \cite{data_mri}}%
    \caption{MRI Image}
      \label{fig:4_2_5}
   \end{subfigure}
\caption{Used Images}
\label{fig:datasetimages}
    \end{figure}
\end{document}

答案3

类似于以下解决方案?请注意,中间子图在其自身中设置minipage,其总宽度是两个“常规”子图加上它们之间的空间之和。我还摆脱了所有\caption*包装器,因为它们似乎没有做太多事情(有用)。代码还注意将整个figure水平居中在页面上。

在此处输入图片描述

\documentclass{article}
\usepackage[demo]{graphicx} %remove 'demo' option in real document
\usepackage{subcaption} % for 'subfigure' environment
\usepackage{ragged2e}  % for '\Centering' macro
\usepackage[]{geometry}   % set page parameters suitably
\begin{document}
\begin{figure}
\Centering
  \begin{subfigure}[t]{0.3\textwidth}
  \Centering
  \includegraphics[width=\textwidth, height=4cm]%
      {boat_gray_256.png}
  Source: Public-Domain Test Images for Homeworks 
  and Projects~\cite{data_bb} 

  \caption{Boat Image}   
  \label{fig:4_2_1}
  \end{subfigure}\hspace{0.05\textwidth}%
  \begin{subfigure}[t]{0.3\textwidth}
  \Centering
  \includegraphics[width=\textwidth, height=4cm]%
      {cameraman_gray_256.png}
  Source: Image Databases, Standard\\ 
  Test Images~\cite{data_lwpcmphlwj}

  \caption{Cameraman Image}
  \label{fig:4_2_2}
  \end{subfigure}

  \bigskip
  \begin{minipage}{0.65\textwidth} % 0.3+0.3+0.05=0.65
  \Centering
  \begin{subfigure}[t]{0.462\textwidth} % 0.3/0.65=0.462
  \Centering
  \includegraphics[width=\textwidth, height=4cm]%
      {lena_gray_256.png}
  Source: Image Databases, Standard Test Images~\cite{data_lwpcmphlwj}

  \caption{Lena Image}
  \label{fig:4_2_3}
  \end{subfigure}
  \end{minipage}

  \bigskip
  \begin{subfigure}[t]{0.3\textwidth}
  \Centering
  \includegraphics[width=\textwidth, height=4cm]%
      {jetplane_gray_256.png}
  Source: Image Databases, Standard \\ 
  Test Images \cite{data_lwpcmphlwj}

  \caption{Jet Plane Image}
      \label{fig:4_2_4}
  \end{subfigure}\hspace{0.05\textwidth}%
  \begin{subfigure}[t]{0.3\textwidth}
  \Centering
  \includegraphics[width=\textwidth, height=4cm]%
      {mri_gray_256.jpg} 
  Source: Northern Arizona University, Gray 
  Scale Images~\cite{data_mri}

  \caption{MRI Image}
  \label{fig:4_2_5}
  \end{subfigure}

  \bigskip
  \caption{Used Images}  
  \label{fig:datasetimages}
  \end{figure}
\end{document}

答案4

我想这height=4cm只是举个例子,否则可能会扭曲图像。请注意,PNG 图像通常不能任意缩放。

话虽如此,您似乎想要一个星形布局。

删除所有\centering无用命令。为了在狭窄的空间中排版源文件,最好使用\raggedright;一个外部命令\centering即可完成其余工作。

我还改用\caption*自制的\source命令,以便以较小的字体打印源文件。

\documentclass{article}
\usepackage{subcaption}
\usepackage[demo]{graphicx}

\newcommand{\source}[1]{{\footnotesize Source: #1\par}}

\begin{document}

\begin{figure}[htp]
\centering

\begin{subfigure}{0.3\linewidth}
\raggedright
\includegraphics[width=\textwidth, height=4 cm]{boat_gray_256.png}
\source{Public-Domain Test Images for Homeworks and Projects \cite{data_bb}}
\caption{Boat Image}\label{fig:4_2_1}
\end{subfigure}\hfill
\begin{subfigure}{0.3\linewidth}
\raggedright
\includegraphics[width=\textwidth, height=4cm]{cameraman_gray_256.png}
\source{Image Databases, Standard   \\ Test Images \cite{data_lwpcmphlwj}}
\caption{Cameraman Image}\label{fig:4_2_2}
\end{subfigure}

\begin{subfigure}{0.3\linewidth}          
\raggedright
\includegraphics[width=\textwidth, height=4 cm]{lena_gray_256.png}
\source{Image Databases, Standard Test Images \cite{data_lwpcmphlwj}}
\caption{Lena Image}\label{fig:4_2_3}
\end{subfigure}

\begin{subfigure}{0.3\linewidth}
\raggedright
\includegraphics[width=\textwidth, height=4cm]{jetplane_gray_256.png}
\source{Image Databases, Standard   \\ Test Images \cite{data_lwpcmphlwj}}
\caption{Jet Plane Image}\label{fig:4_2_4}
\end{subfigure}\hfill
\begin{subfigure}{0.3\linewidth}
\raggedright
\includegraphics[width=\textwidth, height=4cm]{mri_gray_256.jpg}
\source{Northern Arizona University, Gray Scale Images \cite{data_mri}}
\caption{MRI Image}\label{fig:4_2_5}
\end{subfigure}

\caption{Used Images}\label{fig:datasetimages}

\end{figure} 

\end{document}

在此处输入图片描述

不同的布局:

\documentclass{article}
\usepackage{subcaption}
\usepackage[demo]{graphicx}

\newcommand{\source}[1]{{\footnotesize Source: #1\par}}

\begin{document}

\begin{figure}[htp]
\centering

\begin{subfigure}[t]{0.3\linewidth}
\raggedright
\includegraphics[width=\textwidth, height=4 cm]{boat_gray_256.png}
\source{Public-Domain Test Images for Homeworks and Projects \cite{data_bb}}
\caption{Boat Image}\label{fig:4_2_1}
\end{subfigure}\hfill
\begin{subfigure}[t]{0.3\linewidth}
\raggedright
\includegraphics[width=\textwidth, height=4cm]{cameraman_gray_256.png}
\source{Image Databases, Standard   \\ Test Images \cite{data_lwpcmphlwj}}
\caption{Cameraman Image}\label{fig:4_2_2}
\end{subfigure}\hfill
\begin{subfigure}[t]{0.3\linewidth}          
\raggedright
\includegraphics[width=\textwidth, height=4 cm]{lena_gray_256.png}
\source{Image Databases, Standard Test Images \cite{data_lwpcmphlwj}}
\caption{Lena Image}\label{fig:4_2_3}
\end{subfigure}

\bigskip

\begin{subfigure}[t]{0.3\linewidth}
\raggedright
\includegraphics[width=\textwidth, height=4cm]{jetplane_gray_256.png}
\source{Image Databases, Standard   \\ Test Images \cite{data_lwpcmphlwj}}
\caption{Jet Plane Image}\label{fig:4_2_4}
\end{subfigure}\hspace{0.05\textwidth}%
\begin{subfigure}[t]{0.3\linewidth}
\raggedright
\includegraphics[width=\textwidth, height=4cm]{mri_gray_256.jpg}
\source{Northern Arizona University, Gray Scale Images \cite{data_mri}}
\caption{MRI Image}\label{fig:4_2_5}
\end{subfigure}

\caption{Used Images}\label{fig:datasetimages}

\end{figure} 

\end{document}

我使用是0.05\textwidth因为这是顶行图形之间的空间(简单的算术)。可能需要做一些工作来对齐顶行中的标题。

在此处输入图片描述

相关内容