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.

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}

Here, you can see the result that I have obtained

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

share|improve this question
    
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
add comment

3 Answers

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}

enter image description here

share|improve this answer
add comment

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}
share|improve this answer
add comment

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 %.

share|improve this answer
    
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
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.