4

My Problem: I would like to have all images in my Latex document beeing well sized in height and width. Precisly I want, that protrait and landscape images get a predefined size in the document. I got this by this style:

\RequirePackage{ifthen,graphicx}
\newlength{\widthW}
\newlength{\heightH}
\newcommand\includegraphicsJustified[1]{
    \settowidth{\widthW}{\includegraphics{#1}}
    \settoheight{\heightH}{\includegraphics{#1}}
    \ifthenelse{\lengthtest{\widthW > \heightH}}{
        \includegraphics[width=0.40\textwidth]{#1}\\
    }{
        \includegraphics[height=0.35\textheight]{#1}\\
    }
}

The second thing is, I want to use this in a \subfigure because I have a lot of images which have to be side by side.

The problem is, everything works great, but as soon as I try to centering this images I got:

! LaTeX Error: Something's wrong--perhaps a missing \item.

Thats my code:

\begin{figure}
\centering
\subfigure[comment]{\includegraphicsJustified{images/img1.png}  }
\subfigure[comment]{\includegraphicsJustified{images/img2.png}  }
\caption{whole comment}
\end{figure}

Note again: without the \centering command it works.

I tried to add this to my style, to automaticly center all figure elements:

\makeatletter
\let\oldfigure\figure
\def\figure{\@ifnextchar[\figure@i \figure@ii}
\def\figure@i[#1]{\oldfigure[#1]\centering}
\def\figure@ii{\oldfigure\centering}
\makeatother

This works great, but not when I use the \subfigure:

! LaTeX Error: Something's wrong--perhaps a missing \item.

Without the \subfigure I can use my \includegraphicsJustified{} command and it get centered. Note also: When I use the subfigure with a normal \includegraphics{} it works!

Is there anybody out there who could explain this or much better can distribute a solution?

migrated from stackoverflow.com Oct 2 '12 at 6:04

This question came from our site for professional and enthusiast programmers.

  • What package are you using that supports \subfigure, subfigure? This has been replaced by subfig that provides \subfloat. – Werner Oct 1 '12 at 3:29
  • Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Oct 2 '12 at 6:10
3

Try putting the subfigure inside a minipage, see below,

\begin{figure}
\centering
\begin{minipage}{0.5\textwidth}
\subfigure[comment]{\includegraphicsJustified{images/img1.png} }
\subfigure[comment]{\includegraphicsJustified{images/img2.png} }
\end{minipage}
\caption{whole comment}
\end{figure}

I firmly believe that you can carry out the rest of the fine tuning.

For further details, please see http://www.tex.ac.uk/cgi-bin/texfaq2html?label=errmissitem.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.