3

I'm trying to align photos and text vertically and horizontally in the middle of each tabular. I've tried the 'array' package but it seems like I need to define the width of the column. I want the column to be adjusted by max length of any object.

\documentclass{article}
\usepackage{array}
\begin{document}
\begin{table}
    \begin{tabular}{lcr}
        &                   $\downarrow$                   &              \\
        $\rightarrow$ & \rule{4cm}{4cm} & $\leftarrow$ \\
        &                    $\uparrow$                    &
    \end{tabular}
\end{table}
\end{document}

Where I'm using the \rule function in this example. I want to use a regular figure.

How I want it to look...

4

One option is to use adjustbox with export option. Then valign is available as a key to \includegraphics

\documentclass{article}
\usepackage{array}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\begin{document}
\begin{table}
    \begin{tabular}{lcr}
        &                   $\downarrow$                   &              \\
        $\rightarrow$ & \includegraphics[valign=c,width=3cm]{example-image-a} & $\leftarrow$ \\
        &                    $\uparrow$                    &
    \end{tabular}
\end{table}
\end{document}

enter image description here

And another option is to use raisebox

\documentclass{article}
\usepackage{array}
\usepackage{graphicx}
\begin{document}
\begin{table}
    \begin{tabular}{lcr}
        &                   $\downarrow$                   &              \\
        $\rightarrow$ &
            \raisebox{-0.5\height}{\includegraphics[width=3cm]{example-image-a}} & $\leftarrow$ \\
        &                    $\uparrow$                    &
    \end{tabular}
\end{table}
\end{document}

To be precise, this should be (thanks to Manuel)

\raisebox{\dimexpr-0.5\height+\fontdimen22\textfont2\relax}{\includegraphics[width=3cm]{example-image-a}}
  • Perfect... Just perfect. Exactly what I've been trying to achieve. :D Thanks. – Bjartmar Mar 5 '15 at 0:47
  • 1
    IIRC, the correct value would be \dimexpr-0.5\height+\fontdimen22\textfont2\relax – Manuel Mar 5 '15 at 14:50
  • @Manuel Right, next level of procrastination, Thanks :-) – user11232 Mar 5 '15 at 14:54
1

Well \rule has an optional argument to adjust the vertical alignment:

\documentclass{article}
\usepackage{array}
\begin{document}
  \begin{table}
    \begin{tabular}{lcr}
      &                   $\downarrow$                   &              \\
      $\rightarrow$ & \rule[-2cm]{4cm}{4cm} & $\leftarrow$ \\
      &                    $\uparrow$                    &
    \end{tabular}
  \end{table}
\end{document}

rule with lift

  • Thanks for the answer. But I only used the rule command just to add something with large dimension in the table. I'm including figures instead of using black box. I'm sorry, I should've make that clear. – Bjartmar Mar 5 '15 at 0:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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