Skip to content

Commit ed074ba

Browse files
committed
fix: automatically centre images
1 parent 72554c6 commit ed074ba

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/template.latex

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,31 @@ $endif$
220220
\usepackage{float}
221221
\floatplacement{figure}{H}
222222

223+
% Wrap includegaphics in figures with centering...
224+
\usepackage{etoolbox} % For toggle functionality
225+
226+
\newtoggle{infigure} % Create toggle to track if we're inside a figure environment
227+
\togglefalse{infigure} % Initialize as false
228+
229+
% Set toggle when entering/exiting figure environments
230+
\pretocmd{\figure}{\toggletrue{infigure}}{}{}
231+
\apptocmd{\endfigure}{\togglefalse{infigure}}{}{}
232+
233+
% Save the original includegraphics command
234+
\let\oldincludegraphics\includegraphics
235+
236+
% Redefine includegraphics to check if it's already in a figure
237+
\renewcommand{\includegraphics}[2][]{%
238+
\iftoggle{infigure}{%
239+
\oldincludegraphics[#1]{#2}%
240+
}{%
241+
\begin{figure}
242+
\centering
243+
\oldincludegraphics[#1]{#2}
244+
\end{figure}%
245+
}%
246+
}
247+
223248
% Remove "Figure X." prefix from captions
224249
\usepackage{caption}
225250
\captionsetup[figure]{labelformat=empty}

0 commit comments

Comments
 (0)