I am trying to draw over a figure using tikz, using a method for adding scalebars from this answer. The figures that are drawn over this way have extra padding around them (i.e. between the subfigures) that I can't get rid of. Compare the top row of the image below with the bottom row.
I can kind of workaround it by adding an \hskip and manually finding the right number for a give figure (see commented out portion of MWE)
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{tikz}
% Add a scalebar to an image
\newcommand{\scalebar}[5][white]{%
\noindent\begin{tikzpicture}
\draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\fill [fill=black, fill opacity=0.5] (0.02,0.1cm) rectangle (#4/#3+0.12,1cm);
\fill [#1] (0.05,0.2cm) rectangle (#4/#3+0.05,0.4cm);
\draw [#1] (0.00,0.4cm) node[anchor=south west, font=\footnotesize] {{#4}{#5} };
\end{scope}
\end{tikzpicture} %\hskip -1pt % This is my only workaround
}
\begin{document}
\begin{figure}[h]
\centering
\begin{subfigure}{\textwidth}
\caption{}
\includegraphics[width=.3\textwidth]{example-image-golden}
\includegraphics[width=.3\textwidth]{example-image-golden}
\includegraphics[width=.3\textwidth]{example-image-golden}
\end{subfigure}
\begin{subfigure}{\textwidth}
\caption{}
\scalebar{\includegraphics[width=.3\textwidth]{example-image-golden}}{6}{1}{mm}
\scalebar{\includegraphics[width=.3\textwidth]{example-image-golden}}{6}{1}{mm}
\includegraphics[width=.3\textwidth]{example-image-golden}
\end{subfigure}
\end{figure}
\end{document}

outer sep=0? – Feb 28 '19 at 00:12}instead of}%. – John Kormylo Feb 28 '19 at 05:07