I would like to ensure that content is always centred within subfloats (without the need for \centering in each one). This question was asked and answered over 6 years ago but, of the answers, the only one that still works as of January 2020 is:
\usepackage{etoolbox}
\makeatletter
\gappto\@floatboxreset{\centering\appto\@minipagerestore{\centering}}
\makeatother
Unfortunately, to quote the answerer:
but I wouldn't do it, as this would mean that all minipages in a float would get \centering; there are macros that internally use minipage that might be used in a float: also those would receive \centering, which could so end up in unwanted places.
Here is my MWE which uses the linked approach:
\documentclass{article}
\usepackage{subcaption}
\usepackage{etoolbox}
\makeatletter
\g@addto@macro\@floatboxreset\centering % Centre within every float
\makeatother
\makeatletter
\gappto\@floatboxreset{\centering\appto\@minipagerestore{\centering}} % Centre within every subfloat
\makeatother
\begin{document}
\begin{table}
\caption{Table}\label{fig}
\begin{subtable}[H]{0.5\textwidth}
\caption{Subtable}
\begin{tabular}{c}
\hline
Tabular\\
\hline
\end{tabular}
\end{subtable}
\end{table}
\end{document}
Is there an alternate solution which circumvents the issues quoted above?
\centeringin a few places. Any of such hacks has a great chance to cause trouble if another user has placed a feature request for a key doing this, and the feature request went through. – Jan 22 '20 at 02:10