5

I have an image in PDF format like this:

enter image description here

There's a lot of empty space in the bottom half of the image. When I insert the PDF image in main.tex using \includegraphics[width=\textwidth]{4x4_System_Circuit.pdf} the blank space of the image also gets included. Can that blank space somehow be trimmed out? Otherwise, it looks weird.

P.S: You can see the code I used to generate the PDF image here.

2 Answers2

12

Most latex installations come with the pdfcrop command line tool.

Simply run

pdfcrop filename.pdf

This creates a new pdf (filename-crop.pdf) where the excessive whitespace have been removed. And the just include this new file.

As the name suggests, this only work on pdf files.

daleif
  • 54,450
5

You can use

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}

\begin{document}

\begin{figure}[h]
    \centering
    \includegraphics[width=\textwidth, trim = 1cm 2cm 0cm 1cm, clip]{test-image}
\end{figure}
\end{document}

where trim=left bottom right top specifies by how much the image/pdf gets clipped.

Find trim parameters

To find the trim parameters, you can draw an fbox around your image and see the area that will be clipped (marked by a black rectangle). Once you found the correct area, delete the fbox and add the clip key.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}

\begin{document}

\begin{figure}[h]
    \centering
    \fbox{\includegraphics[width=\textwidth, trim = 1cm 2cm 0cm 1cm]{test-image}}
\end{figure}
\end{document}

Alternative: Use standalone document class for your input pdf

As you are producing the input pdf as well, you can set the document class for this pdf (4x4_System_Circuit.pdf) to standalone. This will automatically produce a pdf that has the right size. No clipping will be needed. For information on how to use the standalone class, see the standalone class manual, section 5.

Tom
  • 1,279