【问题标题】:Image numbering depending on the partition number in which the image is displayed图像编号取决于显示图像的分区号
【发布时间】:2019-07-14 18:56:42
【问题描述】:

如何在图 1.1:、图 1.2:、图 2.1:、图 2.2: 中的图像下制作标题,取决于章节编号,而不是文章中所有图像的从 1 开始的顺序

例如代码:

\begin{figure}[htbp]
    \minipage{0.32\textwidth}   
    \centering\includegraphics[width=\linewidth]{images/1.png}
    \caption{caption 1}\label{Fig_1}

    \endminipage\hfill

    \minipage{0.32\textwidth}%
    \centering\includegraphics[width=\linewidth]{images/2.png}
    \caption{caption 2}\label{Fig_2}

    \endminipage\hfill

    \minipage{0.32\textwidth}%
    \centering\includegraphics[width=\linewidth]{images/3.png}
    \caption{caption 3}\label{Fig_3}
    \endminipage
\end{figure}

【问题讨论】:

    标签: image label latex figure caption


    【解决方案1】:

    没有任何额外的包,latex 本身提供了宏\counterwithin,它允许对每个部分的数字进行编号:

    \documentclass{article}
    
    \usepackage{graphicx}
    \counterwithin{figure}{section}
    
    \begin{document}
    
    \section{title}
    
    \begin{figure}[htbp]
        \begin{minipage}{0.32\textwidth}   
    %       \centering
            \includegraphics[width=\linewidth]{example-image-duck}
            \caption{caption 1}
            \label{Fig_1}
        \end{minipage}
        \hfill
        \begin{minipage}{0.32\textwidth}%
    %       \centering
            \includegraphics[width=\linewidth]{example-image-duck}
            \caption{caption 2}
            \label{Fig_2}
        \end{minipage}
        \hfill
        \begin{minipage}{0.32\textwidth}%
    %       \centering
            \includegraphics[width=\linewidth]{example-image-duck}
            \caption{caption 3}
            \label{Fig_3}
        \end{minipage}
    \end{figure}
    
    \end{document}
    

    (如果图像已经与minipage具有相同的宽度,则不需要\centering

    【讨论】:

      【解决方案2】:

      tex.stackechange https://tex.stackexchange.com/questions/28333/continuous-v-per-chapter-section-numbering-of-figures-tables-and-other-docume中有这个问题的答案
      它使用chngcntr 包重新定义了计数器。

      但在我看来,更简单的是使用floatpackage。它允许重新定义浮动环境,具有特定的图形外观、位置等和编号方案。

      \documentclass{article}
      
      \usepackage{graphicx}
      \usepackage{float}
      
      % We define a new float environment called image.
      % htbp means 'images' will be positioned preferably here, then at top, bottom or   
      % on a new page
      % info on labels will go to file xx.lim (list of images)
      % and it will numbered within sections
      \newfloat{image}{htbp}{lim}[section]
      % and we want 'Fig.' to appear on the caption
      \floatname{image}{Fig.}
      \begin{document}
      
      \section{A first section}
      blah blah. Look at image \ref{im1}. blah blah
      \begin{image}
        \centering
        \includegraphics[width=3cm]{example-image}
        \caption{An image}\label{im1}
      \end{image}
      
      \section{A second section}
      blah blah. And now consider images \ref{im2} and \ref{im3}. blah blah
      \begin{image}
        \centering
      \hfill\includegraphics[width=3cm]{example-image}\hfill\includegraphics[width=3cm]{example-image}\hfill\includegraphics[width=3cm]{example-image}\hfill
        \caption{Now a bunch with several images}\label{im2}
      \end{image}
      
      blah blah
      \begin{image}
        \centering
        \begin{tabular}{cc}
          \includegraphics[width=3cm]{example-image}    &\includegraphics[width=3cm]{example-image}\\
          Image A&Image B
        \end{tabular}
        \caption{And two last images}\label{im3}
      \end{image}
      \end{document}
      

      如果您在一个无花果中有多个图像,只需将它们作为任何文本放置即可。在 TeX 中,图像被视为(大)字符,并且适用标准定位方法。在第一个示例中,我使用\hfill 将它们均匀地分布在一条线上,在第二个示例中,我使用表格在图像上包含小 cmets。但是可以使用许多其他方法,例如 minipages。但是,如果您的图像集太长而无法放在一行中,则可能会出现不需要的换行符。

      无关,但任何人都使用float 包,因为它还定义了一个新的放置指令“H”,这或多或少意味着“将浮动放置在此处而不是其他任何地方”。而且修改浮动的图形外观也很有用。

      这是另一种没有浮动包的解决方案

      \documentclass{article}
      
      \usepackage{graphicx}
      \usepackage{chngcntr}
      
      % change counter numbering
      \counterwithin{figure}{section}
      
      \begin{document}
      
      \section{A first section}
      blah blah. Look at images \ref{im1}, \ref{im2} and \ref{im3}. blah blah
      \begin{figure}[h]
        \begin{minipage}{0.3\linewidth}
          \centering
          \includegraphics[width=\linewidth]{example-image}
          \caption{image 1}\label{im1}
        \end{minipage}
        \hfill
        \begin{minipage}{0.3\linewidth}
          \centering
          \includegraphics[width=\linewidth]{example-image}
          \caption{image 2}\label{im2}
        \end{minipage}
        \hfill
        \begin{minipage}{0.3\linewidth}
          \centering
          \includegraphics[width=\linewidth]{example-image}
          \caption{image 3}\label{im3}
        \end{minipage}
        \centering
      \end{figure}
      \end{document}
      

      【讨论】:

      • Merigon,谢谢你而不是告诉我如何在一个容器中处理多个图像 {figure}(在问题描述中添加了示例)?因为当我对这种类型的图像使用您建议的方法时,签名显示在左侧(第一张图像下方),但右侧(第三张)图像显示签名
      • 我不明白你的问题。在我的示例中,标题正确显示在“图形”的中心。如果您想要一个包含多个图像的图形,您必须首先使用任何方法定位它们并将它们包含在浮动中。我用两种方法更新了答案,以在一个图中包含多个图像,但存在许多方法。但标题始终居中。
      • 我的意思是(如示例中的问题) - 1 个块 {figure},其中包含 3 个图像和图像下的 3 个标题 - 图 1.1、图 1.2、图 1.3 和你有 1 个块 {image},其中包含 3 个图像,但只有 1 个编号 Fig. 1.1
      • 这是一个完全不同的问题。图形和派生的浮点数是“浮动”环境。因此,您无法通过将它们并排放置在非浮动环境中来精细控制它们的位置。有一个“subfigure”包允许在一个图中放置两个或多个图像。但它不适用于“浮动”包。此外,您可以使用“capt-of”包从图形中生成标题并手动排版您的图像和标题。但它也不适用于自定义浮动环境。
      • 最好的解决方案是调整 tex.SE 答案中的解决方案,我提到的每个部分编号的数字。要么使用子图,要么将几张带有标题的图片放在小页面中,并将它们全部放在一个独特的图环境中。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-30
      • 1970-01-01
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多