I have to do several figures like this:
\begin{figure}[h!]
\centering
\includegraphics[trim = 9.55cm 1.8cm 10.25cm 4.05cm, clip,width=1\textwidth]{./../ficherosComunes/images/capturaapp/01-actividadprincipal.png}
\caption{Captura de pantalla de ActividadPrincipal.java}
\end{figure}
\begin{figure}[h!]
\centering
\includegraphics[trim = 9.55cm 1.8cm 10.25cm 4.05cm, clip,width=1\textwidth]{./../ficherosComunes/images/capturaapp/02-listadoficheros.png}
\caption{Captura de pantalla de ActividadFicheros.java.}
\end{figure}
\begin{figure}[h!]
\centering
\includegraphics[trim = 9.55cm 1.8cm 10.25cm 4.05cm, clip,width=1\textwidth]{./../ficherosComunes/images/capturaapp/03-listadoficherodetalles.png}
\caption{Captura de pantalla de ActividadFicheroDetalles.java.}
\end{figure}
As it can be seen there's all times repeated trim = 9.55cm 1.8cm 10.25cm 4.05cm, clip,width=1\textwidth
Would it be possible to write it in a variable? I have tried to define a \newcommand{\texttrim}{trim = 9.55cm 1.8cm 10.25cm 4.05cm, clip,width=1\textwidth}
but it doesn't work if I put it as an option. I have also tried to define lengths (to have at least the trimming lengts defined) but they don't work either.
Best Answer
There are several ways to do this:
1. define a new command
(as carsten said already)
You can define the command with an optional argument to be able to pass additional options to
\includegraphics
. You may add the{figure}
stuff if you like.2. define a command to preset the keys
If you use
\settrimming
all following graphics will be trimmed. You can use it in the preamble (then you can use the definition directly and there's no need to wrap it in\settrimming
) or you use it inside a group (like{figure}
env) to scope its effect. Note that you'll need to loadxkeyval.sty
for this way.3. using
\edef
and\expandafter
You can use
\edef
to store the options an then make it usable in the option list by adding two\expandafter
:full MWE example