Centrare il testo in orizzontale e in verticale in LaTeX [chiusa]
Domanda
mi piacerebbe produrre il seguente:
a b
xxxxx xxxxx
1 xxxxx xxxxx
xxxxx xxxxx
xxxxx xxxxx
2 xxxxx xxxxx
xxxxx xxxxx
dove i blocchi di 'x sono le immagini, e 'a', 'b', '1' e '2' sono di testo.
Ecco le mie due tentativi finora:
\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}
che produce:
a b
xxxxx xxxxx
xxxxx xxxxx
1 xxxxx xxxxx
xxxxx xxxxx
xxxxx xxxxx
2 xxxxx xxxxx
E
\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}
che produce:
a b
xxxxx xxxxx
1 xxxxx xxxxx
xxxxx xxxxx
xxxxx xxxxx
2 xxxxx xxxxx
xxxxx xxxxx
Soluzione
È possibile effettuare un nuovo tipo di colonna, o semplicemente aggiungere >{\centering\arraybackslash}
prima m{6cm}
per le due colonne di immagine.
Ad esempio:
\newcolumntype{C}{>{\centering\arraybackslash} m{6cm} } %# New column type
\begin{tabular}{m{1cm}CC} %# Table with two of them
...
La direttiva >
si lascia basicamente iniettare il codice contenuto prima di ogni entrata in quella colonna. Abbiamo bisogno del \arraybackslash
a che fare con l'incompatibilità tra l'ambiente e l'ambiente centering
tabular
. Maggiori informazioni si possono trovare qui.
Altri suggerimenti
Io uso \dummyimage
, perché non ho im.png
. Sostituirlo con \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
}}