4

I need to place three tikz pictures side by side, and assign one caption to the triple and a subcaption to each tikz.

I currently use subcaption package and it works well. However, I need migrate to another template in which subfig package and subfloat command are used. The subcaption package and the subfig package can not be used together, and it is impractical to modify the subfloat related codes. Hence, I need to use other method to achieve the same thing as the subcaption command.

This is what I want: enter image description here

And I use these codes to generate it:

\documentclass[preprint,12pt]{article}

\usepackage{amsmath}
% \usepackage{subfig}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,arrows,automata,calc}

\usepackage{lineno}

\begin{document}
\begin{figure}[!thb]
\begin{minipage}{0.320\textwidth}
\centering
\begin{tikzpicture}
\tikzstyle{main}=[circle, minimum size = 5.5mm, thick, draw =black!80, node distance = 3mm]
\tikzstyle{connect}=[-latex, thick]
  \node[main,fill=black!30] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main] (left_i) [left=of i] {};
  \node[main] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge node {} (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{tikzpicture}
\captionsetup[subfigure]{width=0.8\textwidth}
\subcaption{\small Subcaption (a)}
\label{subfig:Event1}
\end{minipage}%
\begin{minipage}{0.320\textwidth}
\centering
\begin{tikzpicture}
\tikzstyle{main}=[circle, minimum size = 5.5mm, thick, draw =black!80, node distance = 3mm]
\tikzstyle{connect}=[-latex, thick]
  \node[main] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main] (left_i) [left=of i] {};
  \node[main,fill=black!30] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge node {} (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{tikzpicture}
\captionsetup[subfigure]{width=0.8\textwidth}
\subcaption{\small Subcaption (b)}
\label{subfig:Event2}
\end{minipage}%
\begin{minipage}{0.320\textwidth}
\centering
\begin{tikzpicture}
\tikzstyle{main}=[circle, minimum size = 5.5mm, thick, draw =black!80, node distance = 3mm]
\tikzstyle{connect}=[-latex, thick]
  \node[main] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main,fill=black!30] (left_i) [left=of i] {};
  \node[main] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge node {} (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{tikzpicture}
\captionsetup[subfigure]{width=0.8\textwidth}
\subcaption{\small Subcaption (c)}
\label{subfig:Event3}
\end{minipage}
\vspace{-0.2cm}
\captionsetup{width=0.98\textwidth}
\caption{\small Caption}
\label{fig:threeEvents}
\vspace{-0.2cm}
\end{figure}

\section{Conclusion}
We build a linear regression model to predict the next value of each instrument. 

\end{document}

In short, how can I achieve the above configuration WITHOUT using the subcaption package?

  • As long as no \label is used in the mandatory argument of \subfloat, the following emulation of \subfloat should work: \makeatletter\long\def\subfloat[#1]{\@ifnextchar[{\@subfloat{#1}}{\subcaptionbox{#1}}} \long\def\@subfloat#1[#2]{\subcaptionbox[{#1}]{#2}} \makeatother. – user2574 Oct 29 '18 at 7:21
4

Sth like this?

\documentclass[preprint,12pt]{article}

\usepackage{amsmath}
\usepackage{subfig}
\usepackage{caption}
\usepackage{tikz}
\usetikzlibrary{positioning}

\usepackage{lineno}

       \captionsetup[subfloat]{width=0.7\textwidth}
\tikzset{main/.style={circle, minimum size = 5.5mm, thick, draw
=black!80, node distance = 3mm},connect/.style={-latex, thick}}    
\begin{document}
\begin{figure}[!thb]
\begin{minipage}{0.320\textwidth}
\centering
\subfloat[\small Subcaption (a)\label{subfig:Event1}]{
\begin{tikzpicture}
  \node[main,fill=black!30] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main] (left_i) [left=of i] {};
  \node[main] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge node {} (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{tikzpicture}
}
\end{minipage}%
\begin{minipage}{0.320\textwidth}
\centering
\subfloat[\small Subcaption (b)\label{subfig:Event2}]{
\begin{tikzpicture}
  \node[main] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main] (left_i) [left=of i] {};
  \node[main,fill=black!30] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge node {} (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{tikzpicture}
}
\end{minipage}%
\begin{minipage}{0.320\textwidth}
\centering
\subfloat[\small Subcaption~(c)\label{subfig:Event3}]{
\begin{tikzpicture}
  \node[main] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main,fill=black!30] (left_i) [left=of i] {};
  \node[main] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge node {} (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{tikzpicture}
}
\end{minipage}
\vspace{-0.2cm}
\captionsetup{width=0.98\textwidth}
\caption{\small Caption}
\label{fig:threeEvents}
\vspace{-0.2cm}
\end{figure}

\section{Conclusion}
We build a linear regression model to predict the next value of each instrument. 

\end{document}

enter image description here

2

This is more of a long comment. In particular, this answer should not be awarded a green tick because I all that I am doing is rewriting marmot's nice solution in a more compact way. Up votes are, of course, fine:)

Rather than repeating this large chunk of code for each regression model I recommend defining a macro to do this. The only difference between the three different models used is which node is shaded. The code below defines a macro \Model that takes one argument that tells it which node should filled. For example, \Model{1}, \Model{4} and \Model{3} will produce the diagrams in the OP. This is done by adding a new style to each of the nodes and then changing the style for node #1 in the macro (the numbering of the nodes is the order that they appear in the OP).

As shown below, the output is the same as in marmot's solution but the code is shorter and easier to read:

\documentclass[preprint,12pt]{article}

\usepackage{amsmath}
\usepackage{subfig}

\usepackage{caption}
\captionsetup[subfloat]{width=0.7\textwidth}

\usepackage{lineno}

\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
  main/.style={circle, minimum size = 5.5mm, thick, draw
=black!80, node distance = 3mm},
  connect/.style={-latex, thick},
  node 1/.style={}, % default node styles
  node 2/.style={},
  node 3/.style={},
  node 4/.style={},
  node 5/.style={},
  node 6/.style={},
  node 7/.style={},
}

\newcommand\Model[1]{
\begin{tikzpicture}
  \tikzset{node #1/.style={fill=black!30}}% change the style of node #1
  \node[main, node 1] (i)  {\small $i$};
  \node[main, node 2] (above_i) [above left=of i] {};
  \node[main, node 3] (left_i) [left=of i] {};
  \node[main, node 4] (right_i) [right=of i] {};
  \node[main, node 5] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main, node 6] (temp1) [below=of left_i] {};
  \node[main, node 7] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge node {} (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{tikzpicture}
}

\begin{document}
\begin{figure}[!thb]
\begin{minipage}{0.320\textwidth}
\centering
\subfloat[\small Subcaption (a)\label{subfig:Event1}]{ \Model{1} }
\end{minipage}%
\begin{minipage}{0.320\textwidth}
\centering
\subfloat[\small Subcaption (b)\label{subfig:Event2}]{ \Model{4} }
\end{minipage}%
\begin{minipage}{0.320\textwidth}
\centering
\subfloat[\small Subcaption~(c)\label{subfig:Event3}]{ \Model{3} }
\end{minipage}
\vspace{-0.2cm}
\captionsetup{width=0.98\textwidth}
\caption{\small Caption}
\label{fig:threeEvents}
\vspace{-0.2cm}
\end{figure}

\end{document}

You should be able to adapt this idea to typeset other similar models if you need them in other parts of your document. You might also want to include the minipage and caption in the \Model macro.

To confirm that this works, here is the output:

enter image description here

1

Update :

By continuing to use all the power of TikZ to place text through the nodes. This avoids unnecessary loading of unnecessary packages.

This time, to place the legends, I defined three scope environments: one for each figure. This also eliminates the need to use the minipage environment, which further simplifies the code. Each defines a local bounding boxthat I named gauche, milieu and droit (see p 1033 of manual 3.0.1a).

\begin{scope}[local bounding box=gauche]

The nodes are placed 2 mm below their southern anchors on these bounding boxes.

\node[node distance=2mm, below= of gauche.south]{Subcaption (a)};

caption

\documentclass[preprint,12pt]{article}

\usepackage{amsmath}

\usepackage{subfig}
\usepackage{caption}
%\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,arrows,automata,calc}

\usepackage{lineno}

\begin{document}
\begin{figure}[!thb]
\centering
\begin{tikzpicture}
\begin{scope}[local bounding box=gauche]
\tikzstyle{main}=[circle, minimum size = 5.5mm, thick, draw =black!80, node distance = 3mm]
\tikzstyle{connect}=[-latex, thick]
  \node[main,fill=black!30] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main] (left_i) [left=of i] {};
  \node[main] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{scope}
\node[below= 2mm of gauche.south]{Subcaption (a)};

\begin{scope}[xshift=4cm,local bounding box=milieu]
\tikzstyle{main}=[circle, minimum size = 5.5mm, thick, draw =black!80, node distance = 3mm]
\tikzstyle{connect}=[-latex, thick]
  \node[main] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main] (left_i) [left=of i] {};
  \node[main,fill=black!30] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{scope}
 \node[below= 2mm of milieu.south]{Subcaption (b)};

\begin{scope}[xshift=8cm,local bounding box=droit]
\tikzstyle{main}=[circle, minimum size = 5.5mm, thick, draw =black!80, node distance = 3mm]
\tikzstyle{connect}=[-latex, thick]
  \node[main] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main,fill=black!30] (left_i) [left=of i] {};
  \node[main] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{scope}
  \node[below= 2mm of droit.south]{Subcaption (c)};

\end{tikzpicture}
\label{subfig:Event3}
\vspace{-0.2cm}
\captionsetup{width=0.98\textwidth}
\caption{\small Caption}
\label{fig:threeEvents}
\vspace{-0.2cm}
\end{figure}

\section{Conclusion}
We build a linear regression model to predict the next value of each instrument. 

\end{document}

Translated with www.DeepL.com/Translator

Old answer:

Instead of using an additional package, it is also easy to use tikz's possibilities for node placement. On your figures, the easiest way is to place this text in the path connecting the two circular nodes at the bottom:

 \path[line width=0.03cm] (temp1) edge node[shift={(.1,-.7)},font=\small] {Subcaption (b)} (temp2);

caption

\documentclass[preprint,12pt]{article}

\usepackage{amsmath}

 \usepackage{subfig}
\usepackage{caption}
%\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,arrows,automata,calc}

\usepackage{lineno}

\begin{document}
\begin{figure}[!thb]
\begin{minipage}{0.320\textwidth}
\centering
\begin{tikzpicture}
\tikzstyle{main}=[circle, minimum size = 5.5mm, thick, draw =black!80, node distance = 3mm]
\tikzstyle{connect}=[-latex, thick]
  \node[main,fill=black!30] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main] (left_i) [left=of i] {};
  \node[main] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge node[shift={(0,-.7)},font=\small] {Subcaption (a)} (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{tikzpicture}
\captionsetup[subfigure]{width=0.8\textwidth}
%\subcaption{\small Subcaption (a)}
\label{subfig:Event1}
\end{minipage}%
\begin{minipage}{0.320\textwidth}
\centering
\begin{tikzpicture}
\tikzstyle{main}=[circle, minimum size = 5.5mm, thick, draw =black!80, node distance = 3mm]
\tikzstyle{connect}=[-latex, thick]
  \node[main] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main] (left_i) [left=of i] {};
  \node[main,fill=black!30] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge node[shift={(.1,-.7)},font=\small] {Subcaption (b)} (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);

\end{tikzpicture}
\captionsetup[subfigure]{width=0.8\textwidth}
%\subcaption{\small Subcaption (b)}
\label{subfig:Event2}
\end{minipage}%
\begin{minipage}{0.320\textwidth}
\centering
\begin{tikzpicture}
\tikzstyle{main}=[circle, minimum size = 5.5mm, thick, draw =black!80, node distance = 3mm]
\tikzstyle{connect}=[-latex, thick]
  \node[main] (i)  {\small $i$};
  \node[main] (above_i) [above left=of i] {};
  \node[main,fill=black!30] (left_i) [left=of i] {};
  \node[main] (right_i) [right=of i] {};
  \node[main] (right_above_i) [above right=of i, above left=of right_i] {};
  \node[main] (temp1) [below=of left_i] {};
  \node[main] (temp2) [below=of right_i] {};
  \path[line width=0.03cm] (i) edge node {} (above_i);
  \path[line width=0.03cm] (i) edge node {} (left_i);
  \path[line width=0.03cm] (i) edge node {} (right_i);
  \path[line width=0.03cm] (above_i) edge node {} (left_i);
  \path[line width=0.03cm] (right_i) edge node {} (right_above_i);
  \path[line width=0.03cm] (i) edge node {} (right_above_i);
  \path[line width=0.03cm] (temp1) edge node[midway,shift={(.1,-.7)},font=\small]{Subcaption (c)} (temp2);
  \path[line width=0.03cm] (temp1) edge node {} (left_i);
  \path[line width=0.03cm] (temp2) edge node {} (right_i);
\end{tikzpicture}
\captionsetup[subfigure]{width=0.8\textwidth}
%\subcaption{\small Subcaption (c)}
\label{subfig:Event3}
\end{minipage}
\vspace{-0.2cm}
\captionsetup{width=0.98\textwidth}
\caption{\small Caption}
\label{fig:threeEvents}
\vspace{-0.2cm}
\end{figure}

\section{Conclusion}
We build a linear regression model to predict the next value of each instrument. 

\end{document}

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.