3

I would like an axis drawn with TikZ in the corner of the image grid to see the increase in variables clearly. The MWE below results in Figure 1. I have tried putting a \linebreak in between \end{tikzpicture} and \foreach \a which results in Figure 2. Ideally, I'm looking to get something like Figure 3 but without the white background on the tikzpicture i.e. axis very close to the first figure.

\documentclass{article}
\usepackage[demo]{graphics}
\usepackage{tikz}
\usepackage{pgffor}
\usepackage{subcaption}

\begin{document}
\begin{figure}[!htb]
    \centering
    \begin{tikzpicture}
        \draw [->] (0,0) -- (0.5,0) node[right]{\(\sigma_{\theta}\)};
        \draw [->] (0,0) -- (0,-0.5) node[below]{\(\sigma_{\phi}\)};
    \end{tikzpicture}
    \foreach \a in {1,...,2} {
        \foreach \b in {1,...,5} {
            \begin{subfigure}{.185\textwidth}
                \includegraphics[width=\textwidth]{example-image-duck}
                \caption{\((\a,\b)\)}
            \end{subfigure}
        }
        \linebreak
    }
\end{figure}
\end{document}

Figure 1

Problem

Figure 2

Current

Figure 3

Solution

1

Let me know if the following is what you're looking for :)

You can tweak the \vspace{} and \hspace{} to move the axes where you prefer.

\documentclass{article}
\usepackage[demo]{graphics}
\usepackage{tikz}
\usepackage{pgffor}
\usepackage{subcaption}

\begin{document}
\begin{figure}[!htb]
    \hspace{-1cm}   %shifts the tikzpicture to the left 1cm
    \begin{tikzpicture}
        \draw [->] (0,0) -- (0.5,0) node[right]{\(\sigma_{\theta}\)};
        \draw [->] (0,0) -- (0,-0.5) node[below]{\(\sigma_{\phi}\)};
    \end{tikzpicture}
    \vspace{-0.5cm}  %pulls the following pictures up half a cm
    \begin{center}   % Only centers the pictures, not the axes
        \foreach \a in {1,...,2} {
            \foreach \b in {1,...,5} {
                \begin{subfigure}{.185\textwidth}
                    \includegraphics[width=\textwidth]{example-image-duck}
                    \caption{\((\a,\b)\)}
                \end{subfigure}
            }
            \linebreak
        }
    \end{center}    
\end{figure}
\end{document}

produces:

enter image description here

  • 1
    I like the simplicity of this solution – Paddy Roddy Mar 8 at 10:38
2
\documentclass{article}
\usepackage{graphics}
\usepackage{tikz}
\usepackage{pgffor}
\usepackage{subcaption}
\usepackage{stackengine}
\begin{document}
\begin{figure}[!htb]
    \centering
\savestack\myaxes{\raisebox{-23pt}{%
    \begin{tikzpicture}
        \draw [->] (0,0) -- (0.5,0) node[right]{\(\sigma_{\theta}\)};
        \draw [->] (0,0) -- (0,-0.5) node[below]{\(\sigma_{\phi}\)};
    \end{tikzpicture}
}}
    \foreach \a in {1,...,2} {
        \foreach \b in {1,...,5} {
            \begin{subfigure}{.185\textwidth}
               \ifnum\a=1\relax
                 \ifnum\b=1\relax
                   \stackinset{l}{-15pt}{t}{}{\smash{\myaxes}}{%
                     \includegraphics[width=\textwidth]{example-image-duck}%
                   }
                 \else
                   \includegraphics[width=\textwidth]{example-image-duck}
                 \fi
               \else
                 \includegraphics[width=\textwidth]{example-image-duck}
               \fi
                \caption{\((\a,\b)\)}
            \end{subfigure}
        }
        \linebreak
    }
\end{figure}
\end{document}

enter image description here

The following alternate has less coding, but takes more execution, as it performs a \stackinset on each figure. However, the inset is zeroed out after the first use:

\documentclass{article}
\usepackage{graphics}
\usepackage{tikz}
\usepackage{pgffor}
\usepackage{subcaption}
\usepackage{stackengine}
\begin{document}
\begin{figure}[!htb]
    \centering
\savestack\myaxes{\raisebox{-23pt}{%
    \begin{tikzpicture}
        \draw [->] (0,0) -- (0.5,0) node[right]{\(\sigma_{\theta}\)};
        \draw [->] (0,0) -- (0,-0.5) node[below]{\(\sigma_{\phi}\)};
    \end{tikzpicture}
}}
    \foreach \a in {1,...,2} {
        \foreach \b in {1,...,5} {
            \begin{subfigure}{.185\textwidth}
               \stackinset{l}{-15pt}{t}{}{\smash{\myaxes}}{%
                 \includegraphics[width=\textwidth]{example-image-duck}%
               }
               \global\let\myaxes\relax
               \caption{\((\a,\b)\)}
            \end{subfigure}
        }
        \linebreak
    }
\end{figure}
\end{document}

This third alternative zeroes out the meaning of \stackinset after the first use, and restores it after the figure. Thus, it is more efficient in execution than the prior alternative, and still takes less coding than the originally provided solution.

\documentclass{article}
\usepackage{graphics}
\usepackage{tikz}
\usepackage{pgffor}
\usepackage{subcaption}
\usepackage{stackengine}
\let\svstackinset\stackinset
\newcommand\zerostackinset{\gdef\stackinset##1##2##3##4##5##6{##6}}
\begin{document}
\begin{figure}[!htb]
    \centering
\savestack\myaxes{\raisebox{-23pt}{%
    \begin{tikzpicture}
        \draw [->] (0,0) -- (0.5,0) node[right]{\(\sigma_{\theta}\)};
        \draw [->] (0,0) -- (0,-0.5) node[below]{\(\sigma_{\phi}\)};
    \end{tikzpicture}
}}
    \foreach \a in {1,...,2} {
        \foreach \b in {1,...,5} {
            \begin{subfigure}{.185\textwidth}
               \stackinset{l}{-15pt}{t}{}{\smash{\myaxes}}{%
                 \includegraphics[width=\textwidth]{example-image-duck}%
               }
               \zerostackinset
               \caption{\((\a,\b)\)}
            \end{subfigure}
        }
        \linebreak
    }
\end{figure}
\let\stackinset\svstackinset
\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.