图像编号取决于显示图像的分区号

时间:2019-07-14 18:56:42

标签: image label latex figure caption

我如何在图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}

2 个答案:

答案 0 :(得分:1)

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

但我认为,更简单的方法是使用float软件包。它允许重新定义具有特定图形外观,位置等和编号方案的浮动环境。

\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}

enter image description here

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

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

这是没有float软件包的另一种解决方案

\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}

enter image description here

答案 1 :(得分:1)

在没有任何其他软件包的情况下,latex本身提供了宏type PersonInfo = (Int, String, Int) def insertMany(ps: List[PersonInfo]): ConnectionIO[Int] = { val sql = "insert into person (id, name, age) values (?, ?, ?)" Update[PersonInfo](sql).updateMany(ps) } // Some rows to insert val data = List[PersonInfo]( (1,"John", 31), (2,"Alice", 32) ) // To use `quick` see doc https://tpolecat.github.io/doobie/docs/07-Updating.html#setting-up insertMany(data).quick.unsafeRunSync // or insertMany(data).transact(xa) // where `xa` is your `Transactor` ,该宏可以按部分对数字进行编号:

\counterwithin

enter image description here

(如果图像的宽度已经与\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} 相同,则不需要{\centering