Set height and width of an image or figure in LaTeX
LaTeX has several methods by which you can set the height and width of an image. In this case, the graphicx
package will be very useful for you.
In this tutorial, I will show you how to resize an image using some of the options provided by this package. Let me see the topics.
- Set image size with
weight
andheight
option - Set image size with
scale
option
Set image size using weight and height option
First, you need to load the graphicx
package. Now while inserting an image into a LaTeX document by \includegraphics
command, you can specify height and width in square brackets [width=x cm,height=y cm]
with this command.
\documentclass{article} \usepackage{graphicx} \begin{document} \begin{figure}[h] \centering \includegraphics{example-image} \caption{Default size of an image} \end{figure} \begin{figure}[h] \centering \includegraphics[width=6cm,height=4cm]{example-image} \caption{Adjust size of this image with width=6cm,height=4cm} \end{figure} \end{document}
Output:
Set height and width based on \textwidth
You can also set the width and height of the image based on the size of the text width. In this case, you can use the \textwidth
or \linewidth
command to detect the width of the text.
For example, if you want the size of an image to be 50% of the width of the text, you should enter [width=0.5\textwidth]
with the \includegraphics
command.
\documentclass{article} \usepackage{graphicx} \usepackage{lipsum} \begin{document} \section{width=50\% and height=40\% of textwidth} \lipsum[1][1-7] \begin{figure}[h] \centering \includegraphics[width=0.5\textwidth,height=0.4\textwidth]{example-image} \caption{Image size with width=50\% of textwidth,height=40\% of textwidth} \end{figure} \section{width=40\% and height=30\% of textwidth} \lipsum[1][1-7] \begin{figure}[h] \centering \includegraphics[width=0.4\textwidth,height=0.3\textwidth]{example-image} \caption{Image size with width=40\% of textwidth,height=30\% of textwidth} \end{figure} \end{document}
Output:
I would like to give a personal recommendation, while mentioning the size of the image, only mention the width
or height
. If you only set the height
, LaTeX will automatically set the width
to maintain the aspect ratio of the image.
\documentclass{article} \usepackage{graphicx} \usepackage{lipsum} % For dummy text only \begin{document} \section{Using only width} \lipsum[1][1-4] \begin{figure}[h] \centering \includegraphics[width=0.7\textwidth]{example-image} \caption{Image size with width=70\% of textwidth} \end{figure} \section{Using only height} \lipsum[1][1-3] \begin{figure}[h] \centering \includegraphics[height=0.4\textwidth]{example-image} \caption{Image size with width=40\% of textwidth} \end{figure} \end{document}
Output:
Set image size with scale option
A simple option to change the image size is the scale
option. This allows you to set the image size based on its original size. If you want to reduce the image size by 50% of the original size then you have to write this [scale=0.5]
with the \includegraphics
command.
\documentclass{article} \usepackage{graphicx} \begin{document} \begin{figure}[t] \centering \includegraphics{example-image} \caption{Original size of the image} \end{figure} \begin{figure}[h] \centering \includegraphics[scale=0.5]{example-image} \caption{50\% of original size} \end{figure} \begin{figure}[h] \centering \includegraphics[scale=0.3]{example-image} \caption{30\% of original size} \end{figure} \end{document}
Output:
Leave a Reply