我添加新计数器后,图形引用停止工作

我添加新计数器后,图形引用停止工作

我使用amspset文档类来生成考试练习题。我想为这些问题添加一些参考,所以我开始了一个像这样的新计数器(改编自一些 Tex Exchange 帖子)

\newcounter{P}
\newcommand{\plb}[1]{\refstepcounter{P}\label{#1} \textbf{P-\ref{#1}.}}

\begin{problem}
\plb{p1}
A parallel-wire transmission line is constructed of \#6 AWG copper wire
(diameter $d=0.162$ in., conductivity $\sigma_c=5.8\times 10^7$ S/m) with a
12-inch separation in air. Assuming no leakage between the two wires, find
$R'$, $L'$, $G'$, and $C'$. Assume a working frequency of 1 MHz.
\end{problem}

\begin{solution}
Using Table.~\ref{tab:tlparam} and Fig.~\ref{fig:tlempl}, 
\[ Rs = \sqrt{\pi f \mu_c/\sigma_c} = 2.61\times10^{-4}~ \Omega\]
\[ R' = \frac{2R_s}{\pi d} = 4.04\times10^{-2} ~\Omega\text{/m} \]
\[ L' = \frac{\mu_0}{\pi} \ln{\frac{2D}{d}}=2.0~\mu \text{H/m} \]
\[ C' = \frac{\pi \epsilon}{\displaystyle\ln{\frac{2D}{d}}}=5.56 ~\text{pF/m}
\] $G'=0$ because the problem states that there is no leakage between the two
wires.
\end{solution}

\begin{figure}[ht]
\begin{centering}
    \includegraphics{fig24}
    \caption{(Fig.2-4 from FAE) A few examples of transmission lines.}
\end{centering}
\label{fig:tlempl}
\end{figure}

\begin{table}[ht]
\caption{(Table 2-1 from FAE)Transmission-line parameters $R'$, $L'$, $G'$,
and $C'$ for three types of lines.}
    \begin{tabular}{c}
        \hspace{3cm}\includegraphics{tb21}
    \end{tabular}
\label{tab:tlparam}
\end{table}
... and more

现在所有图形引用都停止工作了,我得到的是“图 ”而不是“图 1”。但是表格引用没问题。知道问题可能出在哪里吗?

答案1

您错误地使用了该\centering指令:

\begin{figure}[ht]
\begin{centering} % <- wrong!
    \includegraphics{fig24}
    \caption{(Fig.2-4 from FAE) A few examples of transmission lines.}
\end{centering}
\label{fig:tlempl}
\end{figure}

这是一个\centering命令,而不是centering环境(尽管 LaTeX 不会引发错误并且可以工作)。而是写

\begin{figure}[ht]
\centering
  \includegraphics{fig24}
  \caption{(Fig.2-4 from FAE) A few examples of transmission lines.}
  \label{fig:tlempl}
\end{figure}

您的代码的问题在于引用来自\caption一个组内部形成,因此后续\label命令无法“看到”它。

相关内容