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 having a few issues with vertically aligning table elements. There seems to be too much space either above or below the text or image. Is this to do with the fbox environment? I want both the image and text to be centered vertically in each table cell.

\documentclass[a4paper,11pt]{article}
\usepackage[english]{babel}
\usepackage{graphicx}   
\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}
\usepackage{array}

\newcommand{\mybox}[1]{
    \begin{center}
    \fbox{
    \parbox{0.8\linewidth}{
        \begin{center}
            \begin{tabular}{ c m{4.5in} }
            \includegraphics[height=0.3in]{./myfig} & {#1}
            \end{tabular} 
        \end{center}
        }
     }
    \end{center}
}


\begin{document}

\mybox{hello}

\mybox{hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello}


\end{document}

enter image description here

Edit: Following Gonzalo Medina's suggestion, I get: enter image description here and there is no difference between center and centering.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

You can use a m{length} column type for the first column:

\documentclass[a4paper,11pt]{article}
\usepackage[english]{babel}
\usepackage{graphicx}   
\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}
\usepackage{array}

\newcommand{\mybox}[1]{
    \begin{center}
    \fbox{%
    \parbox{0.8\linewidth}{%
        \begin{center}
            \begin{tabular}{m{0.3in}m{4.5in} }
            \includegraphics[height=0.3in]{example-image-a} & #1
            \end{tabular} 
        \end{center}
        }
     }
    \end{center}%
}


\begin{document}

\mybox{hello}

\mybox{hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello}


\end{document}

enter image description here

I wasn't sure if some of the blank spaces at end of lines were intentional or not; I commented them out. Also take into account that center adds some vertical spacing so perhaps you could consider using \centering instead.

As an alternative, I'd like to propose the tcolorbox package to easily produce your box; you can even customize it even further:

\documentclass[a4paper,11pt]{article}
\usepackage[english]{babel}
\usepackage{graphicx}   
\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}
\usepackage[many]{tcolorbox}

\newcommand\mybox[1]{%
    \begin{tcolorbox}[
      sidebyside,
      lefthand width=.3in,
      colback=white,
      outer arc=0pt,
      arc=0pt.
      colframe=black,
      boxrule=0.4pt,
      segmentation engine=empty
    ]
    \includegraphics[width=.3in]{example-image-a}
    \tcblower
    #1
    \end{tcolorbox}%
}

\begin{document}

\mybox{hello}

\mybox{hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello}


\end{document}

enter image description here

share|improve this answer

You can use valign macro from the adjustbox package in

\includegraphics[valign=c,height=0.3in]{example-image-a} 

Code:

\documentclass[a4paper,11pt]{article}
\usepackage[english]{babel}
\usepackage[export]{adjustbox}  %% export is needed
\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}
\usepackage{array}

\newcommand{\mybox}[1]{%
    \begin{center}
    \fbox{%
    \parbox{0.8\linewidth}{%
        \begin{center}
            \begin{tabular}{ c m{0.75\linewidth} }
            \includegraphics[valign=c,height=0.3in]{example-image-a} & #1
            \end{tabular}
        \end{center}
        }%
     }%
    \end{center}
}


\begin{document}

\mybox{hello}

\mybox{hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello}


\end{document}

enter image description here

share|improve this answer

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.