【问题标题】:How to create own and fancy \sub<float> command如何创建自己和花哨的 \sub<float> 命令
【发布时间】:2010-01-08 03:38:46
【问题描述】:

我正在使用包 subfigurefloat 创建我想要创建的图形和表格,并且我正在尝试创建自己的环境 graph 带有自己的计数器和标题 (solved there,谢谢给dmckee)。现在我想创建\subgraph 命令,它的作用与\subfigure 命令完全相同。

我尝试使用适当的计数器创建自己的命令(Assisted here,感谢 Alexey)。但是使用\ref 命令会出现问题。对\subfigure 的引用返回2.1(a),但对\subgraph 的引用返回1

当我试图找出如何解决这个问题时,我阅读了subfig 手册,在那里我找到了带有示例的\newsubfloat 命令。第一个错误是在subfigure 中使用subfig 的命令,我被困在那里。如果我使用subfigure,我可以访问\subfigure,但不能强制\subgraph工作,当我使用subfig时,我可以在graph中访问\subfloat,但不能在figure中访问,\ref返回1.0a 而不是 1.1 (a)

subfig 包定义:

\newfloat{graph2}{tbph}{lom}[chapter]
\restylefloat*{graph2}
\floatstyle{plain}
\floatname{grap2}{Graph2}
\captionsetup[graph2]{position=top}
\newcommand{\listofGraphs}{\listof{Graph2}{List of Graphs}}
\newsubfloat[position=bottom,listofformat=subsimple]{graph2}

定义我自己的\subgraph

\newfloat{graph1}{H}{lop}[chapter]
\floatname{graph1}{Graph1}
\newcounter{GraphOne}[graph1]
\def\theGraphOne{\alph{GraphOne}}
\newcommand{\subgraph}[2][]{
\captionof{subGraph}{#1} #2
}

\newfloat{subGraph}{H}{lop}[graph1]
\floatname{subGraph}{}

请帮助我了解\label\ref 命令的工作原理(我认为我的解决方案崩溃了,因为\label\caption 之前)和/或强制subfig 包按我的意愿工作。

感谢您的任何想法,请善待我的英语。

克劳利

改进:

通过使用 caption 包,我可以创建新计数器 (subGraph) 并在其环境之外使用它。正确引用两个计数器(子图和图)的唯一方法是在 \subgraph 之前使用 \captionof{graph}

所以,我的新问题是:如何在子图之前执行\captionof{graph} 并在它们下方排版?以及如何强制\ref 显示 1.1-a 而不是 1.1.1

附件:

subfigure 的代码:(返回 &lt;chapter&gt;.&lt;figure&gt; (&lt;subfigure&gt;) 正确。

\begin{figure}
\subfigure[sub-caption]{\includegraphics{fig1}\label{fig:1}}
\caption{main caption}
\end{figure}
\ref{fig:1}

subfig 的代码:(返回 &lt;chapter&gt;.&lt;graph2&gt;-1&lt;subfigure&gt;)不正确。

\begin{graph2}
\subfloat[sub-caption]{\includegraphics{fig1}\label{fig:2}}
\caption{main caption}
\end{graph2}
\ref{fig:2}

我的代码:(返回 &lt;chapter&gt;.&lt;graph1&gt;.&lt;subgraph&gt; 但标题显示相同的“地址”)

\begin{graph1}
\captionof{graph1}{main caption}
\subgraph[sub-caption]{\includegraphics{fig1}\label{fig:3}}
\end{graph1}
\ref{fig:3}

【问题讨论】:

    标签: latex label counter caption subfigure


    【解决方案1】:

    我认为您的 subfig 解决方案应该可以工作(无论如何,subfigure 已被弃用)。错误引用的问题可能与您有关using \label incorrectly。您必须在\caption 之后有\label 命令,或者作为它的一部分:

    \begin{figure}
    \caption{A Figure}
    \label{fig}
    \end{figure}
    

    \begin{figure}
    \caption{A Figure%
    \label{fig}}
    \end{figure}
    

    编辑:以下“适合我”。正如我所说,\label\caption 之后:

    \documentclass{report}
    \usepackage{float}
    \usepackage{subfig}
    \newfloat{graph2}{tbph}{lom}[chapter]
    \restylefloat*{graph2}
    \floatstyle{plain}
    \floatname{grap2}{Graph2}
    \captionsetup[graph2]{position=top}
    \newcommand{\listofGraphs}{\listof{Graph2}{List of Graphs}}
    \newsubfloat[position=bottom,listofformat=subsimple]{graph2}
    \begin{document}
    \chapter{Test}
    \section{Test s}
    
    \begin{graph2}
    \subfloat[sub-caption]{\fbox{Fig 1}}
    \caption{main caption}
    \label{fig:1}
    \end{graph2}
    
    \begin{graph2}
    \subfloat[sub-caption]{\fbox{Fig 2}}
    \caption{main caption}
    \label{fig:2}
    \end{graph2}
    
    Graph~\ref{fig:1} is the first graph, and~\ref{fig:2} is the second.
    
    \end{document}
    

    这会产生:

    Graph 1.1 is the first graph, and 1.2 is the second.
    

    【讨论】:

    • 是的,我同意\label 命令在\caption 之后的立场。我对标准浮点数没有问题,重点在\subfloat 并引用它。我习惯使用 \subfigure[sub-caption]{\includegraphics{}\label{fig:1}} \caption{main caption}\label{fig}
    • 嗯。我不确定我是否理解。如果您有一个显示您的问题的小示例文档,请在此处发布。
    • 我已经用我的进度和部分代码更新了问题。我的测试.tex 文件很难阅读
    【解决方案2】:

    我现在无法详细说明,但您想使用 \refstepcounter 而不是 \addtocounter。

    【讨论】:

    • 可能我没写清楚。有什么办法告诉\label“忘记章节计数器并存储GraphOne”?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多