# centering a \hbox

I'm trying to center a collection of nested \hbox and \vbox without any succes :-(

Here is the code I use:

\begin{figure}[h]
\center{
\vbox{\hbox{%
\includegraphics{imageA}~%
\includegraphics{imageB}~%
\includegraphics{imageC}}%
\hbox{%
\includegraphics{imageD}~%
\includegraphics{imageE}~%
\includegraphics{imageF}}}%
\caption{text}
}
\end{figure}


The desirable result will be with this image centered in the middle of the page.

-
My problem is that I need to use the specific syntaxis I provided, I have to use the tex commands \vbox and \hbox. Any suggestions? –  EvaMonclús Mar 21 '13 at 19:45
Why are you forced to use \hbox and \vbox? –  Matthew Leingang Mar 21 '13 at 20:17
@user17888 why are you forced to use a syntax that doesn't work instead of the syntax in either of the posted answers that does work? If you are forced to use commands that don't work then we can not help. –  David Carlisle Mar 21 '13 at 21:03
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Dec 6 '14 at 20:16

Neither \hbox nor \vbox are supported LaTeX commands for use in a document, and \center is the internal command for the center environment (and doesn't take an argument.) Also don't use [h] on its own as it makes it very hard for LaTeX to find a good place for the float so most likely it will go to the end of the document.

\begin{figure}[hpt]
\centering
\includegraphics{imageA}~%
\includegraphics{imageB}~%
\includegraphics{imageC}%

\includegraphics{imageD}~%
\includegraphics{imageE}~%
\includegraphics{imageF}%
\caption{text}

\end{figure}

-

You might be better off using a tabular environment:

\documentclass{article}

%\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\newcommand\mybone{\tikz{\fill[blue!20] (0,0) rectangle (1,2);}}

\begin{figure}[h]
\centering
\begin{tabular}{ccc}
\mybone & \mybone & \mybone \\
\mybone & \mybone & \mybone
\end{tabular}
\caption{Error of the algorithm measured against a hand-made segmentation of the Metatarsal%
\ldots why am I kidding? I don't know what I'm talking about\ldots}
\end{figure}

\end{document}


-

It's hard to understand why you're forced to use an unsupported syntax.

However the problem is that \vbox doesn't start horizontal mode, so no matter what \centering or other declaration you give, the \vbox will be placed at the left margin; it's just the same feature you're using inside the \vbox: the two \hboxes are piled one above the other because they don't start horizontal mode. Adding \leavevmode will do.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\leavevmode
\vbox{\hbox{%
\includegraphics{imageA}
\includegraphics{imageB}
\includegraphics{imageC}}
\hbox{%
\includegraphics{imageD}
\includegraphics{imageE}
\includegraphics{imageF}}
\caption{text}
}
\end{figure}
\end{document}


The \center command is wrong. I've also removed useless ~ and %.

-
Thanks very much for the different answers. In thi end, I solved it, adding a minipage environment which encapsulates all the tex commands. –  EvaMonclús Mar 22 '13 at 15:35