如何创建自己的奇特 \sub<float> 命令
题
我正在使用包 subfigure
和 float
创建我想要创建的图形和表格,并且我正在尝试创建自己的环境 graph
有自己的计数器和标题(在那里解决了, ,感谢 dmckee)。现在我想创建 \subgraph
命令的作用与 \subfigure
命令。
我尝试使用适当的计数器创建自己的命令(在这里提供协助, ,感谢阿列克谢)。但使用时出现问题 \ref
命令。参考 \subfigure
回报 2.1(一) 但参考 \subgraph
回报 1.
当我试图找出如何解决这个问题时,我读到 subfig
手册,我在哪里找到的 \newsubfloat
命令并带有示例。第一个错误是在使用 subfig
的命令在 subfigure
我被困在那里了。如果我使用 subfigure
我可以访问 \subfigure
但不能强迫 \subgraph
工作,当我使用 subfig
我可以访问 \subfloat
在 graph
但不在 figure
和 \ref
回报 1.0a 代替 1.1(一).
定义为 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
)并在其环境之外使用它。如何正确引用计数器(子图和图)的唯一方法是使用 \captionof{graph}
前 \subgraph
.
所以,我的新问题是:如何执行 \captionof{graph}
在子图之前并在它们下面排版?以及如何强制 \ref
显示 1.1-a 而不是 1.1.1
附件:
代码为 subfigure
: :(返回 <chapter>
.<figure>
(<subfigure>
) 正确的。
\begin{figure}
\subfigure[sub-caption]{\includegraphics{fig1}\label{fig:1}}
\caption{main caption}
\end{figure}
\ref{fig:1}
代码为 subfig
: :(返回 <chapter>
.<graph2>-1<subfigure>
)不正确。
\begin{graph2}
\subfloat[sub-caption]{\includegraphics{fig1}\label{fig:2}}
\caption{main caption}
\end{graph2}
\ref{fig:2}
我的代码:(返回 <chapter>
.<graph1>
.<subgraph>
但标题显示相同的“地址”)
\begin{graph1}
\captionof{graph1}{main caption}
\subgraph[sub-caption]{\includegraphics{fig1}\label{fig:3}}
\end{graph1}
\ref{fig:3}
解决方案
我认为你的 subfig
解决方案应该有效(subfigure
无论如何已被弃用)。参考文献错误的问题可能与您有关 使用 \label
不正确地. 。您必须拥有 \label
命令 后 这 \caption
, ,或作为其中的一部分:
\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.
其他提示
我现在无法详细说明,但您想使用 efstepcounter 而不是 \addtocounter。