Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
1  
Welcome to TeX.SX! –  Papiro Feb 3 at 14:51

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.