1

I am trying to get my hands dirty with tikzpicture. I'm providing below a mock-up of the setup I have at my end. The code I'm providing below might not be the best way of doing things but this is what I have right now.

\begin{figure*}[t!]
\centering%
\begin{tikzpicture}

\node [draw] at (0,0){\includegraphics[width=.090\textheight]{Image 1} };
\node [draw] at (3,2) {\includegraphics[width=.100\textheight]{Image 2} };

% For the numbering of the images because I have to refer these individual images later in the text. 
\node at (-1,-1.1){\colorbox{white}{\ref{f:Image 1}}};
\node at (1.9,0.7){\colorbox{white}{\ref{f:Image 2}}};

\end{tikzpicture}
\caption{Caption text.}
\cl{%
\item\label{f:Image 1}
\item\label{f:Image 2}
}%
}%
\label{f:Main_Method}
\end{figure*}

My goal is to get rid of the extra (a) (b) from the main caption text at the bottom. Could anyone please help with this?

Many thanks

Update (Working code)

I have a massive latex document so I'm providing a simplified example here. I am using tikzpicture in many places and I would prefer sticking to the same to avoid large changes.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[inline]{enumitem}
\usepackage{xspace}


\providecommand{\cl}[1]{\begin{enumerate*}[label=(\alph*)]#1\end{enumerate*}}


\begin{document}

\begin{figure*}[t!]
\centering%
\begin{tikzpicture}

\node [draw] at (0,0){\includegraphics[width=.5\textwidth]{Image 1.png} };
\node [draw] at (8,0) {\includegraphics[width=.5\textwidth]{Image 2.png} };

% For the numbering of the images because I have to refer these individual images later in the text. 
\node at (-2.5,-1){\colorbox{white}{\ref{f:Image 1}}};
\node at (5.5,-1){\colorbox{white}{\ref{f:Image 2}}};

\end{tikzpicture}

\caption{Caption text.
\cl{%
\item\label{f:Image 1}%
\item\label{f:Image 2}%
}%
}%
\label{f:Main_Method}
\end{figure*}

\end{document}

Output----

enter image description here

My goal is to get rid of the extra (a) (b) from the main caption text at the bottom.

10
1

You can perhaps remove the \cl thing altogether, and use \phantomsubcaption from the subcaption package instead.

Load the package and set reference format with

\usepackage{subcaption}
\captionsetup{subrefformat=parens}

Add {\phantomsubcaption\label{...}} for each subfigure. Each \phantomsubcaption should be in its own group.

Finally use \subref instead of \ref in the nodes making the labels.

In the code below I also add a second figure where I demonstrate how to make something similar without any explicit coordinates. If you have a bunch of these already, there's probably not any point in changing all of them, but just to show an idea. The second image is placed relative to the first, and the subfigure-labels are placed using the technique described in https://tex.stackexchange.com/a/106836/.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning} % added for the second example, remove if you don't use it
\usepackage[inline]{enumitem}
\usepackage{xspace}
\usepackage{subcaption}
\captionsetup{subrefformat=parens}


% this style is just an example for an alternative method of adding subcaptions like this
% the first argument is for adding additional node options to the node with the subfigure label
% can be used if you want to move the label somewhere else
\tikzset{
  addsubcap/.style 2 args={
    append after command={(\tikzlastnode.south west) node[above right=15pt,fill=white,#1] {\subref{#2}}}
  }
}

\begin{document}

% figure with minimal changes
\begin{figure*}[t!]
\centering%
\begin{tikzpicture}

\node [draw] at (0,0){\includegraphics[width=.5\textwidth]{example-image-a}};
\node [draw] at (8,0) {\includegraphics[width=.5\textwidth]{example-image-b}};

% For the numbering of the images because I have to refer these individual images later in the text. 

% use \subref insteaf of \ref
\node at (-2.5,-1){\colorbox{white}{\subref{f:Image 1}}};
\node at (5.5,-1){\colorbox{white}{\subref{f:Image 2}}};

% note that each subcaption has to be in a group ({...}) or environment
{\phantomsubcaption\label{f:Image 1}}%
{\phantomsubcaption\label{f:Image 2}}%

\end{tikzpicture}
\caption{Caption text.}%
\label{f:Main_Method}
\end{figure*}


% alternative which you can ignore
\begin{figure*}[t!]
\centering%
\begin{tikzpicture}

\node [draw, name=img1, addsubcap={}{f:Image 3}] {\includegraphics[width=.5\textwidth]{example-image}};
% an example using yshift to move the label up
\node [draw,right=of img1, addsubcap={yshift=1cm}{f:Image 4}] {\includegraphics[width=.5\textwidth]{example-image}};

\end{tikzpicture}%
% note that each subcaption has to be in a group ({...}) or environment
{\phantomsubcaption\label{f:Image 3}}%
{\phantomsubcaption\label{f:Image 4}}%
\caption{Caption text.}
\label{f:Main_Method}
\end{figure*}
\end{document}

enter image description here

2
  • Thank you @Torbjørn T. The phatomsubcaption method worked perfectly (didn't have to make a lot of changes). I did try to search for this myself online but I didn't come across this or a better lead. Is there anything I can do to have a better reference to features like this or this would only come with more latex experience? Jul 10 '20 at 11:39
  • @PrabhakarRay Good question ... I think I learned of it from some question I saw on this site. (One of many things I've learned here probably.) I'm sure it could be found by searching, though finding the right search terms may not be easy. Jul 10 '20 at 15:08

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.