1

I am using subfig package inside the document class "nature". It is not working. Is there any other way to draw subfigures in this class?

\documentclass{nature}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{amsmath,scalerel}
\usepackage{bm}
\usepackage{amssymb}\usepackage{graphicx}
\usepackage{multirow}
\usepackage{adjustbox}
\usepackage{epstopdf}
\usepackage[utf8]{inputenc}
\usepackage[margin=2.5cm]{geometry}
\usepackage{enumitem}
%\usepackage{caption}
\usepackage{pdflscape}
\usepackage{subfig}    
%\usepackage{pgfplots}
\usepackage{lipsum}% 

\usepackage{tikz, wrapfig,array}
\usetikzlibrary{trees}
\usetikzlibrary{calc,patterns,
    decorations.pathmorphing,
    decorations.markings, shapes.geometric, graphs, graphs.standard, quotes,shapes,chains,scopes,positioning,arrows}

\usetikzlibrary{arrows.meta}
\begin{document}
\begin{figure}
\centering
\subfigure[Simple order]{\begin{tikzpicture}[{<[scale=2.5,
          length=3,
          width=3]}-,grow=right,solid node/.style={circle,draw,inner sep=1,fill=black}]
   % \tikzstyle{every node}=[circle,draw]
    \node[solid node,label=left:{$\mu_1$}]{}
       child{node[solid node,label=above:{$\mu_2$}]{} child { node[solid node,label=above:{$\mu_3$}]{} child { node[solid node,label=right:{$\mu_4$}]{} }}}
        ;
\end{tikzpicture}\label{Fig_Simple_Order}
}
\subfigure[Tree order]{\begin{tikzpicture}[{[scale=2.5,
          length=3,
          width=3]<}-,grow=right,level 1/.style={sibling distance=5mm},solid node/.style={circle,draw,inner sep=1,fill=black}]
   % \tikzstyle{every node}=[circle,draw]
    \node[solid node,label=left:{$\mu_1$}]{}
       child { node[solid node,label=right:{$\mu_4$}]{} }
        child { node[solid node,label=right:{$\mu_3$}]{} }
        child { node[solid node,label=right:{$\mu_2$}]{} }
    ;
\end{tikzpicture}\label{Fig_Tree_Order}
}
\end{figure}
\end{document}
3
  • Welcome to TeX.Stackexchange! Oct 5, 2018 at 21:41
  • 1
    Please note that the subfig package was superseded by the subcaption package
    – BambOo
    Oct 5, 2018 at 21:58
  • 1
    Give \usepackage[caption=false]{subfig} a try. And no, I don't see that (my) subcaption package has superseded the subfig package, especially not in use cases where the caption package is incompatible to the document class used.
    – user2574
    Oct 6, 2018 at 8:19

1 Answer 1

1

I see three problems here:

  1. subfig is loading the caption package which is incompatible to the nature document class (since nature re-defines \caption on its own). This can be prevented by adding the option caption=false to subfig.
  2. The command subfig offers is called \subfloat (and not \subfigure).
  3. \subfloat expects \@captype to be defined. But the nature document class re-defines figure without setting \@captype in its own definition. So we need to set \@captype for ourself.
\documentclass{nature}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{amsmath,scalerel}
\usepackage{bm}
\usepackage{amssymb}\usepackage{graphicx}
\usepackage{multirow}
\usepackage{adjustbox}
\usepackage{epstopdf}
\usepackage[utf8]{inputenc}
\usepackage[margin=2.5cm]{geometry}
\usepackage{enumitem}
\usepackage{pdflscape}
\usepackage[caption=false]{subfig}
%\usepackage{pgfplots}
\usepackage{lipsum}% 

% Offer \setcaptiontype to set \@captype - This is needed by \subfloat
\makeatletter
\newcommand\setcaptiontype[1]{\edef\@captype{#1}\ignorespaces}
\makeatother

\usepackage{tikz, wrapfig,array}
\usetikzlibrary{trees}
\usetikzlibrary{calc,patterns,
    decorations.pathmorphing,
    decorations.markings, shapes.geometric, graphs, graphs.standard, quotes,shapes,chains,scopes,positioning,arrows}

\usetikzlibrary{arrows.meta}
\begin{document}
\begin{figure}
\setcaptiontype{figure}
\centering
\subfloat[Simple order]{\begin{tikzpicture}[{
2
  • Thank you Axel. It is working but there is one problem. The caption does not stick to the graph position. It is appearing on the last page. Please help if possible. Oct 7, 2018 at 9:34
  • @SatyaPrakash I'm not familiar with the requirements of Nature, but this is written in nature.cls: "Nature wants things in the order: title, ...figure legends" and "Redefine the figure and table environments. The new figure environment defers printing of all figure captions until the end of the document and prints them in sans serif font. The \includegraphics command is ignored since Nature wants figures as separate files." So it seems to me that this is intentional and the figure content (i.e. the sub-figures) must be delivered as separate file.
    – user2574
    Oct 7, 2018 at 10:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .