0

I wonder, but couldn't find an existing answer to that.

So I want to crop an image and then resize it to fit the page width. I get two errors Missing number, treated as zero. {img.png} and Illegal unit of measure (pt inserted). {img.png} (both referring to line y). Output seems to be okay (also cropped and resized).

At first, I thought it was because of line x, because of that, it is split up like that over 3 lines. It works when I comment out before the word "trim", but I need that. Line x was double checked against different sources but I couldn't find an error.

\usepackage[pdftex]{graphicx}
%...
\begin{figure}[h]
    %   h (here) - same location
    \centering
    \includegraphics[trim=(0pt 30pt 0pt 0pt),% line x
    clip=true,width=\linewidth]
    {img.png} % line y, Error reported to be here
\end{figure}

To the comment: You're probably right and it is more obvious to do resizing and cropping seperately. But it is well defined: (Quoting Martin Scharrer from Crop an inserted image?)

Note that all scaling/resizing is applied after the trimming. If you want the original image be scaled to 5cm width and then 50% clipped, just resize the clipped half to a width of 2.5cm afterwards

1
  • Personally, I always separate the two to make sure they are done in the right order. Commented Aug 25, 2019 at 7:12

2 Answers 2

1

1) Correct syntax:

\includegraphics[trim=0pt 30pt 0pt 0pt,...]{example-image}

(no parentheses after trim=; note that the unit is bp if you don't write any).

2) I would suggest not specifying the driver yourself to graphicx, as autodetection works fine as far as I can tell, you risk making a suboptimal choice, and may forget to update it if you later decide to recompile the document with a different engine.

Good:

\usepackage{graphicx}

“Bad”:

\usepackage[pdftex]{graphicx}

Full example:

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}[htbp]
  \centering
  \includegraphics[trim=0pt 30pt 0pt 0pt,clip=true,width=\linewidth]%
                  {example-image}
\end{figure}

\end{document}
0

Actually, one can use parentheses, but use curly brackets { and }, not round ones ( and ) (look closely), that mistake happened to me.

Correct code:

\usepackage{graphicx} %Thanks frougon for the tip with [pdftex]
%...
\begin{figure}[h]
    %   h (here) - same location
    \centering
    \includegraphics[trim={0pt 30pt 0pt 0pt},% line x
    clip=true,width=\linewidth]
    {img.png} % line y, Error reported to be here
\end{figure}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .