Skip to content

Instantly share code, notes, and snippets.

@Abdelkrim
Created February 15, 2020 15:59
Show Gist options
  • Save Abdelkrim/b3633f337e210fa40b12e871ad90da74 to your computer and use it in GitHub Desktop.
Save Abdelkrim/b3633f337e210fa40b12e871ad90da74 to your computer and use it in GitHub Desktop.
sphinx, latex, resize figures that are too wide for the page and ensure they take the full width of the page
% Made by ALT-F1 SPRL, Abdelkrim Boujraf
%\usepackage{bookmark}
%\usepackage{charter}
%\usepackage[defaultsans]{lato}
%\usepackage{inconsolata}
% \usepackage{pbsi}
% \usepackage[T1]{fontenc}
% \usepackage[T1]{fontenc}
% \usepackage{accanthis}
\usepackage{graphicx}
% Determine if the image is too wide for the page.
\makeatletter
\def\ScaleIfNeeded{%
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother
% Resize figures that are too wide for the page.
\let\oldincludegraphics\includegraphics
\renewcommand\includegraphics[2][]{%
\oldincludegraphics[width=\ScaleIfNeeded]{#2}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment