1

I have asked help before in order to use subfigimg with label in here: https://tex.stackexchange.com/questions/387837/how-to-use-subfigimg-macro-and-label. which @Skillmon helped me solved, however i encounter a new problem using subfigimg when putting the subfigimg in a merged cell like in this case:

\documentclass[preview,border=4mm]{standalone}

\usepackage{graphicx}
\usepackage{xparse}

\newcounter{subfigs}[figure]
\renewcommand*{\thesubfigs}{\thefigure.\alph{subfigs}}

\makeatletter
\NewDocumentCommand{\subfigimg}{s O{} m D<>{10pt} O{2\baselineskip} m}{%
    \IfBooleanTF{#1}%
        {\@subfigimg{#2}{#3}{#6}{0}{#4}{#5}}%
        {\@subfigimg{#2}{#3}{#6}{1}{#4}{#5}}%
}
\newcommand*{\@subfigimg}[6]{%
  \bgroup%
  \advance\c@figure by #4%
  \refstepcounter{subfigs}%
  \ifx\relax#3\relax\else%
  \label{#3}%
  \fi%
  \setbox1=\hbox{\includegraphics[#1]{#2}}% Store image in box
  \leavevmode\rlap{\usebox1}% Print image
  \rlap{\hspace*{#5}\raisebox{\dimexpr\ht1-#6\relax}{(\alph{subfigs})}}% Print label
  \phantom{\usebox1}% Insert appropriate spcing
  \egroup%
}

\makeatother

\begin{document}
\begin{figure}
  \centering
  \begin{tabular}{p{0.5\linewidth}@{}p{0.5\linewidth}}
     \subfigimg[width=\linewidth]{example-image-a}{fig:s11}
      &
     \subfigimg[width=\linewidth]{example-image-b}{fig:s12}\\
    \multicolumn{2}{c}{\subfigimg[width=0.5\linewidth]{example-image-c}<30pt>[3\baselineskip]{}}
  \end{tabular}
  \caption{bla bla bla}
  \label{fig:1}
\end{figure}
See subfigures \ref{fig:s11} and \ref{fig:s12} of figure~\ref{fig:1}
\end{document}

In here the last image label is not working well as the location is off. I tried to solve it by using the location options (<30pt>[3\baselineskip]) and while it does move horizontal, it doesn't move verticaly. i.e., changing <30pt> will move the label but not changing [3\baselineskip].

if anyone can have a fix for this it would be great.

Liron Levy
  • 29
  • 5

1 Answers1

1

In the header of your table, you define two columns that act like a \parbox (\begin{tabular}{p{0.5\linewidth}@{}p{0.5\linewidth}}). Now, you have a \multicolumn where you redefine the column type (\multicolumn{2}{c}{image}). Contrary to the other columns, this is a normal column where no line breaks are allowed -- therefore, any vertical space inserted by \subfigimgis ignored.

The trick is to make this cell multi-line compatible again. Basically, you want to either use a \parbox in the column definition and put \centering in front of the subfigure, or keep the current column definition and put the subfigure in a \parbox:

\documentclass[preview,border=4mm]{standalone}

\usepackage{graphicx}
\usepackage{xparse}

\newcounter{subfigs}[figure]
\renewcommand*{\thesubfigs}{\thefigure.\alph{subfigs}}

\makeatletter
\NewDocumentCommand{\subfigimg}{s O{} m D<>{10pt} O{2\baselineskip} m}{%
    \IfBooleanTF{#1}%
        {\@subfigimg{#2}{#3}{#6}{0}{#4}{#5}}%
        {\@subfigimg{#2}{#3}{#6}{1}{#4}{#5}}%
}
\newcommand*{\@subfigimg}[6]{%
  \bgroup%
  \advance\c@figure by #4%
  \refstepcounter{subfigs}%
  \ifx\relax#3\relax\else%
  \label{#3}%
  \fi%
  \setbox1=\hbox{\includegraphics[#1]{#2}}% Store image in box
  \leavevmode\rlap{\usebox1}% Print image
  \rlap{\hspace*{#5}\raisebox{\dimexpr\ht1-#6\relax}{(\alph{subfigs})}}% Print label
  \phantom{\usebox1}% Insert appropriate spcing
  \egroup%
}

\makeatother

\begin{document}

\begin{figure}
  \centering
  \begin{tabular}{p{.5\linewidth}@{}p{.5\linewidth}}
     \subfigimg[width=\linewidth]{example-image-a}{fig:s11}
      &
     \subfigimg[width=\linewidth]{example-image-b}{fig:s12}\\
     \multicolumn{2}{c}{\parbox{.5\linewidth}{\subfigimg[width=\linewidth]{example-image-c}<30pt>[3\baselineskip]{}}}\\
     \multicolumn{2}{p{\linewidth}}{\centering\subfigimg[width=0.5\linewidth]{example-image-c}<30pt>[3\baselineskip]{}}\\
  \end{tabular}
  \caption{bla bla bla}
  \label{fig:1}
\end{figure}
See subfigures \ref{fig:s11} and \ref{fig:s12} of figure~\ref{fig:1}

\end{document}
Andreas
  • 955
  • Your code is not compilable, because there is no example-image-d available. You should change that to example-image or the d to one of a, b, or c. – Skillmon Sep 12 '17 at 19:05
  • @Skillmon You're right -- sorry for the typo! I had already made the change locally but somehow still inserted the old version here. :-) – Andreas Sep 12 '17 at 19:08