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.

  • 1
    Welcome to TeX.SE! Please edit your question and post a minimal working example starting with \documentclass{...} and ending with \end{document}. – M. Al Jumaily Jul 08 '20 at 23:46
  • 1
    What package does \cl come from? Somewhat related: https://tex.stackexchange.com/questions/150367/best-way-to-make-family-photo-album-in-latex/150481?r=SearchResults&s=1|62.3550#150481 – John Kormylo Jul 09 '20 at 02:58
  • Also related: https://tex.stackexchange.com/questions/275852/how-to-put-a-subcaption-inside-a-tikzpicture (but the solution given there is a bit impractical because the main figure counter in a subfigure reference is not correct by default). – Marijn Jul 09 '20 at 07:07
  • Perhaps this is an oversimplified example, or I'm missing something obivous, but I don't really see why you need to use TikZ. Wouldn't something like https://gist.github.com/TorbjornT/dd3a49e0a904007d43cab82f6a316dab work? – Torbjørn T. Jul 09 '20 at 18:39
  • @M.AlJumaily Thank you. I have updated my question. Apologies for any inconvenience. I hope it is better now. – Prabhakar Ray Jul 09 '20 at 19:32
  • @JohnKormylo My bad. I have some custom commands defined in my latex script and I'm losing track of all these commands. Forgot to add it here that I use \providecommand{\cl}[1]{\begin{enumerate}[label=(\alph)]#1\end{enumerate*}} to create a \cl command. – Prabhakar Ray Jul 09 '20 at 19:36
  • @Marijn Thank you for your suggestion. I will check it out. – Prabhakar Ray Jul 09 '20 at 19:36
  • @TorbjørnT. 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. – Prabhakar Ray Jul 09 '20 at 19:36
  • Tip: for examples with images it's convenient to use example-image as a filename. That image (and other similar images) is installed along with the mwe package, so they will be available to most users. That said, your example, after changing the image names, doesn't actually work. I get a "missing number treated as zero" error when the \cl macro is used. Change to \caption[]{... and it works. – Torbjørn T. Jul 09 '20 at 22:11
  • @TorbjørnT. Thank you for the tip. I will keep this in mind in future. – Prabhakar Ray Jul 10 '20 at 11:36

1 Answers1

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

Torbjørn T.
  • 206,688
  • 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? – Prabhakar Ray 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. – Torbjørn T. Jul 10 '20 at 15:08