如何创建自己的、奇特的 \sub;命令

发布于 2024-08-17 03:58:18 字数 3046 浏览 8 评论 0原文

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

我尝试使用适当的计数器创建自己的命令(这里提供了帮助,感谢 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 包按我想要的方式工作。

谢谢你的任何想法,并对我的英语仁慈一点。

Crowley

改进:

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

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

附件:

subfigure 的代码:(返回

() 正确的

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

subfig 代码:(返回 .-1) 不正确。

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

我的代码:(返回 ..< code>但标题显示相同的“地址”)

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

I'm using packages subfigure and float to create figures and tables that I want to create and I'm trying to create my own environment graph with its own counter and caption (solved there, thanks to dmckee). Now I'd like to create \subgraph command which will do exactly the same as \subfigure command.

I tried create my own command with propreate counter (Assisted here, thanks to Alexey). But problem appears with using \ref command. Reference to \subfigure returns 2.1(a) but reference to \subgraph returns 1.

As I tried to find out how to solve this I read subfig manual, where I've found \newsubfloat command with an example. First error was in use of subfig's commands in subfigure and I got stuck there. If I use subfigure I can access \subfigure but can't force \subgraph working, when I use subfig I can acces \subfloat in graph but not in figure and \ref returns 1.0a instead of 1.1 (a).

definition by subfig package:

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

definition my own \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}{}

Please help me with understanding how \label and \ref commands work (I think my solution collapses because \label is before \caption) and/or with forcing subfig package to work as I want.

Thank you for any idea and be merciful to my english.

Crowley

Improvement:

By using caption package I can create new counter (subGraph) and use it outside its environment. Only way how to have both counter (subgraph and graph) correcly referred is using \captionof{graph} before \subgraph.

So, my new question is: How to execute \captionof{graph} before subgraphs and typeset in below them? And how to force \ref to show 1.1-a instead of 1.1.1

Atachements:

Code for subfigure: (Returns <chapter>.<figure> (<subfigure>) correct.

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

Code for subfig: (Returns <chapter>.<graph2>-1<subfigure>) incorrect.

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

My code: (Returns <chapter>.<graph1>.<subgraph> but caption shows the same "adress")

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

偏爱自由 2024-08-24 03:58:18

我认为您的 subfig 解决方案应该可以工作(subfigure 无论如何已被弃用)。错误引用的问题可能与您 使用 有关\标签不正确。您必须将 \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.

I think your subfig solution should work (subfigure is deprecated anyway). The issue with the wrong references might have to do with you using \label incorrectly. You must have the \label command after the \caption, or as a part of it:

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

or

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

Edit: the following "works for me". As I said, the \label is after the \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}

This produces:

Graph 1.1 is the first graph, and 1.2 is the second.
如果没结果 2024-08-24 03:58:18

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

I can't elaborate right now, but you want to use \refstepcounter instead of \addtocounter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文