I want to wrap a macro around figure-env to make my document more readable. Here is minimal example of how it is now:
\documentclass[10pt,a4paper]{article}
\usepackage{keyval}
\makeatletter
\define@key{image}{pos}{\def\i@pos{#1}} % define key-val
\setkeys{image}{pos=!htbp} % set default
\newcommand{\image}[2][]{%
\begingroup%
\setkeys{image}{#1}% set passed key-vals
\begin{figure}[\i@pos] % use positon
\centerline{\includegraphics[width=\textwidth]{#2}}
\end{figure}
\endgroup%}
\makeatother
\begin{document}
\end{document}
but it seems that the default position !htbp
is not set, because if i set it directly in \begin{figure}[!htbp]
it works perfectly fine and the images are positioned correctly.
Edit:
I added \begin{document}
and \end{document}
as suggested in the comments to make it compileable.
I appreciate you help.
\documentclass{...}
, the required\usepackage
's,\begin{document}
, and\end{document}
. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.\centerline
shouldn't usually be used in latex (it is a relic of the plain tex base) and it does nothing with an image that is\textwidth
wide.\textwidth
her is only because I usually provide more parameters where the images are scaled down if it looks better. Is there a better way to center it?