1

I use PDF figures that are output by Excel with excessive whitespace. There are only a few standard sizes, so I would like to define re-usable variable to set in the [trim = ???] option for the \includegraphics[]{} command.

I have tried putting this at the beginning:

\newcommand{\exsff}{trim = {1in 3.5in 1in 3.5in}}

and this when I insert the graphic:

\includegraphics[width=1\linewidth, \exsff]{figure_name}

but I get an error. If I hardcode it in like this, it works:

\includegraphics[width=1\linewidth, trim = {1in 3.5in 1in 3.5in}]{figure_name}

Any suggestions?

  • 1
    \setkeys{Gin}{trim=1in 3.5in 1in 3.5in} should set the default trim setting – David Carlisle Mar 16 '15 at 18:57
  • I don't want to set the default for the whole document. I want to have about 3 different sizes for my most common formats, and the rest I can handle individually. For example. I would like to say

    [trim = \xxx], [trim = \yyy], or [trim = \zzz]

    where I can define xxx, yyy, and zzz as a list of the four parameters I need. As in, xxx = {1in 2in 1in 2in} and so on.

    – jamesssss Mar 16 '15 at 19:43
  • The question linked as duplicate doesn't really address the problem: the solution given there, e.g. using [scale=\scalefactor] instead of [\scaleconfig]) doesn't work for trim. This question is rather a duplicate of https://tex.stackexchange.com/questions/222043/how-to-expand-a-macro-into-viewport-argumentsincludegraphics . – jeremie Nov 28 '19 at 13:40

1 Answers1

1

You can define new keys; here I define one, but you can do \definetrim as many times as you want, with different arguments.

\documentclass{article}
\usepackage{graphicx}

\makeatletter
\newcommand{\definetrim}[2]{%
  \define@key{Gin}{#1}[]{\setkeys{Gin}{trim=#2,clip}}%
}
\makeatother

\definetrim{exsff}{1in 0.5in 1in 0.5in}

\begin{document}

\includegraphics{example-image-a}

\bigskip

\includegraphics[exsff]{example-image-a}

\end{document}

enter image description here

Production note. I changed the values for the trimming in order to adapt them to the available example picture.

egreg
  • 1,121,712