基于 \subfigure 包的新命令

基于 \subfigure 包的新命令

我尝试创建一个新命令来插入照片,但它开始让我不知所措。我尝试了三种不同的方法,要么我得到了一个难以理解的错误,要么它没有正常工作。我在这里向你介绍我的尝试:

\documentclass[a4paper,12pt, twoside]{article}
\usepackage{fontspec}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{gensymb}
\usepackage{float}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{indentfirst}
\usepackage{siunitx}
\usepackage{polski}
\usepackage[utf8]{inputenc}
\usepackage{scrextend}
\usepackage{subfigure}
\usepackage{hyperref}
\usepackage{ccaption}

\graphicspath{ {access path} }

\begin{document}

%The first way%
\newfloat{picture}{thp}{lop} 
\floatname{picture}{Zdjęcie}
\newcommand{\listofpictures}{\listof{picture}{Spis zdjęć}}
%Allows you to insert only one photo. I can't put several at once.

%The second way%
\makeatletter
\newcounter{subphoto}[photo]
\newif\ifphototopcap
\newif\ifsubphototopcap
\newcommand{\p@subphoto}{\thephoto}
\newcommand{\thesubphoto}{(\alph{subphoto})}
\newcommand{\@thesubphoto}{\thephoto\hskip\subfiglabelskip}
\newcommand{\@@thesubpgoto}{\thephoto}
\newcommand{\ext@subphoto}{\ext@photo}
\newcommand{\l@subphoto}{\@dottedxxxline{\ext@subphoto}{2}{3.8em}{2.5em}}
\newcounter{lomdepth}
\setcounter{lomdepth}{1}
\newcommand{\subphoto}{\subfigure}
\newcommand{\@makesubphotocaption}{\@makesubfigurecaption}
\ifhyperrefloaded
\newcommand\theHsubphoto{\thephoto.\arabic{subphoto}}
\newcommand{\toclevel@subphoto}{1}
\fi
\makeatother
%It's based on the code contained in the \subfigure documentation [ftp://ftp.gust.org.pl/TeX/obsolete/macros/latex/contrib/subfigure/subfigure.pdf][1] I use packages \subfigure and \hyperref in this case.

%The third way%
\newsubfloat{photo}
%Based on the \ccaption package. There is the same error as in the second example.

%Inserting a photo%
\begin{photo}[!tbp]
\begin{center}
\begin{subphoto}[b]{0.3\textwidth}
\includegraphics[width=1\linewidth]{A.png}
\caption{CaptionA.}
\end{subphoto}
\begin{subphoto}[b]{0.3\textwidth}
\includegraphics[width=1\linewidth]{B.png}
\caption{CaptionB.}
\end{subphoto}
\caption[Main caption.][Main caption.}
\end{center}
\end{photo}

\listofphotos
\end{document}

错误:!LaTeX 错误:命令 \c@subfigure 已定义。或名称 \end... 非法,请参阅手册第 192 页。

请参阅 LaTeX 手册或 LaTeX Companion 了解解释。输入 H 可立即获得帮助。...

l.113 \newcounter{subfigure} [图]?

感谢您的帮助。

答案1

使用该newfloat包,您可以用来\DeclareFloatingEnvironment[name={Photo}]{photo}声明一个新的浮动环境 namend phototkat 也接受subphoto

请注意,我使用了该subcaption包而不是弃用的subfigure包。

\documentclass[a4paper,12pt, twoside]{article}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{newfloat}
\DeclareFloatingEnvironment[name={Photo}]{photo}
\usepackage{hyperref}

\begin{document}
\begin{photo}[!tbp]
\begin{center}
\begin{subphoto}[b]{0.3\textwidth}
\includegraphics[width=1\linewidth]{example-image}
\caption{CaptionA.}
\end{subphoto}
\begin{subphoto}[b]{0.3\textwidth}
\includegraphics[width=1\linewidth]{example-image}
\caption{CaptionB.}
\end{subphoto}
\caption[Main caption.]{Main caption.}
\end{center}
\end{photo}

\listofphotos
\end{document}

在此处输入图片描述

答案2

您应该决定是否使用subfiguresubcaption。但是,前者已经过时,应该用 代替subfig

\documentclass[a4paper,12pt, twoside]{article}
\usepackage{fontspec}
\usepackage{float}
\usepackage{graphicx}
\usepackage{polski}
\usepackage{subfig}
\usepackage{hyperref}

\newfloat{photo}{thp}{lop}
\floatname{photo}{Zdjęcie}
\newcommand{\listofphotos}{\listof{photo}{Spis zdjęć}}
\newsubfloat{photo}
\setcounter{lopdepth}{2}

\begin{document}

\begin{photo}[!tbp]
\centering
\subfloat[Caption A]{\includegraphics[width=0.3\textwidth]{example-image}}
\subfloat[Caption B]{\includegraphics[width=0.3\textwidth]{example-image}}
\caption[Main caption.]{Main caption.}
\end{photo}

\listofphotos

\end{document}

更现代的newfloat包装选择

\documentclass[a4paper,12pt, twoside]{article}
\usepackage{fontspec}
\usepackage{newfloat}
\usepackage{graphicx}
\usepackage{polski}
\usepackage{subfig}
\usepackage{hyperref}

\DeclareFloatingEnvironment[
  fileext=lop,
  placement=htp,
  listname={Spis zdjęć},
  name=Zdjęcie,
]{photo}
\newsubfloat{photo}
\setcounter{lopdepth}{2}

\begin{document}

\begin{photo}[!tbp]
\centering
\subfloat[Caption A]{\includegraphics[width=0.3\textwidth]{example-image}}
\subfloat[Caption B]{\includegraphics[width=0.3\textwidth]{example-image}}
\caption[Main caption.]{Main caption.}
\end{photo}

\listofphotos

\end{document}

版本subcaption

\documentclass[a4paper,12pt, twoside]{article}
\usepackage{fontspec}
\usepackage{caption,subcaption}
\usepackage{newfloat}
\usepackage{graphicx}
\usepackage{polski}
\usepackage{hyperref}

\DeclareFloatingEnvironment[
  fileext=lop,
  placement=htp,
  listname={Spis zdjęć},
  name=Zdjęcie,
]{photo}
\DeclareCaptionSubType[alph]{photo}
\captionsetup[subphoto]{list=true}

\begin{document}

\begin{photo}[!tbp]
\centering
\begin{subphoto}[b]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image}
\caption{Caption A}
\end{subphoto}
\begin{subphoto}[b]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image}
\caption{Caption A}
\end{subphoto}
\caption[Main caption.]{Main caption.}
\end{photo}

\listofphotos

\end{document}

在此处输入图片描述

相关内容