When I insert figures into my tex,sometimes it goes out of the page. Can you please suggest a method to avoid this.


adjustbox is your friend. Load adjustbox with export option:


And add max width=\linewidth in the options of \includegraphics. The images will be scaled only if they are broader than the \textwidth/\linewidth (as the case may be)

\usepackage{showframe}   %% just for demo
\includegraphics[width=2\textwidth,,max width=\linewidth]{example-image-a}

\includegraphics[width=0.5\textwidth,,max width=\linewidth]{example-image-a}

enter image description here

You can make a macro if you like:

  \oldincludegraphics[#1,max width=\linewidth]{#2}}

Now you can use


as usual.

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.