3

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

6

adjustbox is your friend. Load adjustbox with export option:

\usepackage[export]{adjustbox}

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)

\documentclass{article}
\usepackage{showframe}   %% just for demo
\usepackage[export]{adjustbox}
\begin{document}
\noindent
\includegraphics[width=2\textwidth,,max width=\linewidth]{example-image-a}

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

enter image description here

You can make a macro if you like:

\let\oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{%
  \oldincludegraphics[#1,max width=\linewidth]{#2}}

Now you can use

\includegraphics[width=2\textwidth]{example-image-a}

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.