2

I'm looking for a macro like,

\newcommand{\figu}[3]{
\begin{figure}[H]
\scalebox{#3}
{\begin{center}
{\includegraphics[width=13 cm, height=8 cm]{#1}}
\end{center}}

\vspace{-0.2cm}
\caption{\hspace{0.25cm}#2\label{f:#1}}
\end{figure}
}

This does not work, but works fine if I erase the \scalebox. Thanks.

1
  • 2
    remove the scalebox (you can not have vertical material in scalebox, and (pehaps) add a scale= option to includegraphics (depending what you want this to do) Note it is usually wrong to specify both height= and width= as that distorts the image, just use one or the other. Commented Nov 20, 2020 at 18:00

1 Answer 1

2

Well, \scalebox works in center, but not the other way round; and a center environment within a figure environment is usually frowned upon since it introduces unwanted vertical space, see Should I use center or centering for figures and tables?. I propose here a slightly different implementation

\documentclass{article}

\usepackage{graphicx,float}

\newcommand{\figu}[3][]{
\begin{figure}[H] % <--- do you REALLY need/want this?
\centering
\includegraphics[#1]{#2}
\vspace{-0.2cm}% <--- do you REALLY need/want this?
\caption{\hspace{0.25cm}% <--- do you REALLY need/want this?
#3\label{f:#2}}
\end{figure}
}

\begin{document}

\figu[width=\linewidth]{example-image-a}{Caption of one figure}

\figu[scale=.4]{example-image-b}{Caption of another figure}

\end{document}

enter image description here

I find it very strange that you force a 13/8 ratio for all pictures; also the vertical and horizontal spaces you are inserting manually look very suspicious to me.

2
  • thanks! it seems however that the first argument must be typed in full "scale=...", I guess typing "scale=..." cannot be avoided that easily
    – florin
    Commented Nov 20, 2020 at 19:48
  • 1
    @florin It can, but there might be situations where you want to pass different options. You can replace this code by \includegraphics[scale=#1]{#2} but then you will be allowed to pass only the scale option to \includegraphics. In my experience this is counter-productive.
    – campa
    Commented Nov 20, 2020 at 19:58

You must log in to answer this question.

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