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 have the following table

\begin{tabular}{ll}
\includegraphics{tag.png} & bla bla bla.\\
\includegraphics{tag.png} & \\
\includegraphics{tag.png} & Store project\\
\includegraphics{tag.png} & Gestures\\
\includegraphics{tag.png} & Screenshot\\
\includegraphics{tag.png} & Tagging\\
\end{tabular}

Now I'd like to achieve that the second column consumes all the remaining page width and the text should be centered vertically in the cell. I achieve either one of this but no both together. Any hints?

share|improve this question
    
A tip: If you indent lines by 4 spaces, then they are marked as a code sample. You can also highlight the code and click the "code" button (with "101010" on it). –  lockstep Mar 11 '11 at 15:58
add comment

3 Answers

up vote 2 down vote accepted
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tabularx,makecell}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}

\begin{tabularx}{\linewidth}{@{} l X @{}}
\makecell{\includegraphics{tag.png}} & bla bla bla.\\
\makecell{\includegraphics{tag.png}} & \\
\makecell{\includegraphics{tag.png}} & Store project\\
\makecell{\includegraphics{tag.png}} & Gestures\\
\makecell{\includegraphics{tag.png}} & Screenshot\\
\end{tabularx}

\end{document}
share|improve this answer
    
@Herbert This is basically the same as my solution, except the first column has a specfied width. Why does using lX (with the same redefinition of X) not work? –  Alan Munn Mar 11 '11 at 16:47
    
@Alan: Because l is aligned to its baseline but m is aligned to its centerline. –  Martin Scharrer Mar 11 '11 at 16:51
    
@Herbert: Thanks i also tried your solution but then I can't generate a PDF: <pictures//tag.png, id=198, 54.9553pt x 55.70813pt> <use pictures//tag.png> <pictures//tag1.png, id=199, 53.44969pt x 54.2025pt> <use pictures//tag1.png> Underfull \hbox (badness 10000) in paragraph at lines 323--324 <use pictures//tag.png> <use pictures//tag.png> ! Extra alignment tab has been changed to \cr. <template> ...egin \relax \d@llarend \endtemplate l.332 \end{tabularx} ? –  RoflcoptrException Mar 11 '11 at 16:54
    
@Martin I understand the difference between l and m, but why should the specification of one column (i.e. the l) affect the vertical spacing in the next column which is m? For example, if you just use tabular{lm} the text in the m column is vertically centred. –  Alan Munn Mar 11 '11 at 16:58
1  
@Roflcoptr: you have forgotten a `\\` at one tabular line or more columns used than specified. –  Herbert Mar 11 '11 at 17:06
show 3 more comments

Use the tabularx package: (the vertical bars are included just to show the centering).

\documentclass{article}
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\begin{tabularx}{\textwidth}{|X|X|}
 \rule{1in}{1in} & This is some text. This is some more text. This is even more text.
\end{tabularx}

\end{document}

This doesn't do exactly what you want, because it uses two X columns rather than one. For some reason that I don't understand, using

\begin{tabularx}{\textwidth}{|l|X|}

fails to make the text in the X column vertically centred.

share|improve this answer
    
Thanks. I just tried that but i centers horizontally not vertically. –  RoflcoptrException Mar 11 '11 at 16:11
    
I've updated my answer. It's not exactly what you want, but it might do the job. –  Alan Munn Mar 11 '11 at 16:32
add comment

Herbert's answer is correct. However, if you don't want or can't specify the width of the first column you could use the following code and have it measured automatically.

\documentclass{article}
\usepackage{array}
\usepackage{tabularx}
\makeatletter
\newcolumntype{L}{>{\VC}l<{\endVC}}%
\renewcommand*{\tabularxcolumn}[1]{m{#1}}

\newbox\mybox
\newenvironment{VC}{%
    \begin{lrbox}{\mybox}%
}{%
    \end{lrbox}%
    \parbox[c]{\wd\mybox}{\usebox\mybox\@finalstrut\@arstrutbox}
}
\makeatother

\begin{document}
\begin{tabularx}{\textwidth}{LX}
    \rule{1in}{1in} & Text \\
    \rule{1in}{2in} & Other Text Ag\strut \\
    \rule{1in}{1in} & 
    Very very very very very very very very 
    Very very very very very very very very 
    Very very very very very very very very 
    Very very very very very very very very 
    long text \\
\end{tabularx}
\end{document}
share|improve this answer
    
see my edited example, it does the same with column type l –  Herbert Mar 11 '11 at 18:44
    
Thanks @Herbert! I didn't know makecell before. –  Martin Scharrer Mar 11 '11 at 18:48
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.