0

I tried to make a new command to insert photos, but it began to overwhelm me. I tried in three different ways and either I got an unintelligible mistake or it didn't work as it should. I present you my trials here:

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

Error: ! LaTeX Error: Command \c@subfigure already defined. Or name \end... illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ...

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

Thank you for your help.

2

With the newfloat package you can use \DeclareFloatingEnvironment[name={Photo}]{photo} to declare a new floating environment namend photo tkat also accepts subphoto.

Please note that I have used the subcaption package instead of the deprecated subfigure package.

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

enter image description here

  • Thank you so much. I sat a few days and I couldn't do it. – Wierszokleta Mar 22 at 20:51
2

You should decide whether using subfigure or subcaption. However, the former is obsolete and should be replaced by 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}

Alternative with the more modern newfloat package

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

The subcaption version

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.