Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

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
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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