![引用子图](https://linux22.com/image/276962/%E5%BC%95%E7%94%A8%E5%AD%90%E5%9B%BE.png)
我正在使用subfigure
一些图像。为了在文本中引用它们,我使用命令\autoref{fig:test}
。但这并不重要,问题与\ref
命令相同。
为了缩短我使用的名称:\addto\extrasngerman{\def\figureautorefname{Abb.}}
并使用阿拉伯数字代替字符:\renewcommand*\thesubfigure{\arabic{subfigure}}
问题(仍然没有上述修改):它引用了
11
,但我希望它被称为
1.1
梅威瑟:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[hidelinks]{hyperref}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\addto\extrasngerman{\def\figureautorefname{Abb.}}
\renewcommand*\thesubfigure{\arabic{subfigure}}
\begin{document}
\section{Test}
Hello. This is some text. I'm referring to a the test image (\autoref{fig:Test1}). Or to the second image with the ref command (Abb. \ref{fig:Test2}). What I want to have: (Abb. 1.2)
\begin{figure}[h]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{bmp0_test_image.png}
\caption{TestCaption1}
\label{fig:Test1}
\end{subfigure}%
~
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{bmp0_test_image.png}
\caption{TestCaption2}
\label{fig:Test2}
\end{subfigure}
\caption{Test-Figure}\label{fig:TestFigure}
\end{figure}
\end{document}
答案1
如果你想让字幕显示为(1.1)测试标题1, 添加
\DeclareCaptionSubType*[arabic]{figure}
到序言部分,删除对的修改
\thesubfigure
,即将其\addto
改为\addto\extrasngerman{\def\figureautorefname{Abb.}}
如果你想保留字幕(1)测试标题1,在序言部分添加以下内容:
\makeatletter \renewcommand\p@subfigure{\thefigure.} \makeatother
据我所知,对子图的引用包括
\p@subfigure\thesubfigure
。通过重新定义前者以包含句点,该句点包含在引用中。
完整示例,第一个选项被注释:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[hidelinks]{hyperref}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
%% OPTION 1
%\DeclareCaptionSubType*[arabic]{figure}
%\addto\extrasngerman{\def\figureautorefname{Abb.}}
%% OPTION 2
\addto\extrasngerman{\def\figureautorefname{Abb.}}
\renewcommand*\thesubfigure{\arabic{subfigure}}
\makeatletter
\renewcommand\p@subfigure{\thefigure.}
\makeatother
\begin{document}
\section{Test}
Hello. This is some text. I'm referring to a the test image (\autoref{fig:Test1}). Or to the second image with the ref command (Abb. \ref{fig:Test2}). What I want to have: (Abb.~1.2)
\begin{figure}[h]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{example-image-a}
\caption{TestCaption1}
\label{fig:Test1}
\end{subfigure}%
~
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{example-image-b}
\caption{TestCaption2}
\label{fig:Test2}
\end{subfigure}
\caption{Test-Figure}\label{fig:TestFigure}
\end{figure}
\end{document}
答案2
检查是否不需要将您的更改\renewcommand*\thesubfigure{\arabic{subfigure}}
为类似的东西\renewcommand*\thesubfigure{.\arabic{subfigure}}
,带有明确的点。对我有用。
在另一个主题中,我会把\label{}
里面因此\caption{}
LaTeX 知道这个标签用于:
\begin{figure}[h]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{bmp0_test_image.png}
\caption{\label{fig:Test1}TestCaption1}
\end{subfigure}%
~
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{bmp0_test_image.png}
\caption{\label{fig:Test2}TestCaption2}
\end{subfigure}
\caption{\label{fig:TestFigure}Test-Figure}
\end{figure}