2010-05-05 10 views
14

Je voudrais produire ce qui suit:Centrer Texte Horizontalement et Verticalement dans LATEX

 a  b 
    xxxxx xxxxx 
1 xxxxx xxxxx 
    xxxxx xxxxx 

    xxxxx xxxxx 
2 xxxxx xxxxx 
    xxxxx xxxxx 

Lorsque les blocs de « X 'sont des images, et « a », « b », « 1 » et « 2 » sont du texte.

Voici mes deux tentatives à ce jour:

\begin{figure} 
\begin{center} 
\begin{tabular}{ccc} 
& a & b \\ 
1 & \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} & 
    \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} \\ 
2 & \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} & 
    \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} \\ 
\end{tabular} 
\end{center} 
\end{figure} 

qui produit:

 a  b 
    xxxxx xxxxx 
    xxxxx xxxxx 
1 xxxxx xxxxx 

    xxxxx xxxxx 
    xxxxx xxxxx 
2 xxxxx xxxxx 

Et

\begin{figure} 
\begin{center} 
\begin{tabular}{m{1cm}m{6cm}m{6cm}} 
& a & b \\ 
1 & \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} & 
    \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} \\ 
2 & \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} & 
    \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} \\ 
\end{tabular} 
\end{center} 
\end{figure} 

qui produit:

a  b 
    xxxxx xxxxx 
1 xxxxx xxxxx 
    xxxxx xxxxx 

    xxxxx xxxxx 
2 xxxxx xxxxx 
    xxxxx xxxxx 
+0

Pour les futurs lecteurs, s'il vous plaît vérifier: http://tex.stackexchange.com/questions/12703/how-to-create-fixed-width-table-columns-with-text-raggedright-centered-raggedlef – Bernhard

Répondre

12

Vous pouvez faire un nouveau type de colonne, ou simplement ajouter >{\centering\arraybackslash} avant m{6cm} pour les deux colonnes d'image.

Par exemple:

\newcolumntype{C}{>{\centering\arraybackslash} m{6cm} } %# New column type 
\begin{tabular}{m{1cm}CC}        %# Table with two of them 
... 

La directive > vous permet d'injecter essentiellement le code contenu avant chaque entrée dans cette colonne. Nous avons besoin du \arraybackslash pour gérer l'incompatibilité entre l'environnement centering et l'environnement tabular. More info can be found here.

4

J'utilise \dummyimage, parce que je n'ai pas im.png. Remplacez-le par \includegraphics{im.png}.

\font\dummyfont = cmr10 at 100pt 
\def\dummyimage{{\vbox to 100pt{\vfil\hbox to 100pt{\hfil\dummyfont A\hfil}\vfil}}} 

\hfil\vbox{ 
\halign{&\hfil\ $\vcenter{\hbox{#}}$\strut \ \hfil\cr 
&a&b\cr 
1&\dummyimage&\dummyimage\cr 
2&\dummyimage&\dummyimage\cr 
}} 
+0

Ce est TeX, pas LaTeX, non? – Svante

+1

@Svante: Oui. Je ne vois rien dans la réponse d'Alexey qui causerait des problèmes dans Latex. –