Graphics, Figures & TablesVertical and horizontal Alignment in Table Cells with Image

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
crobar
Posts: 12
Joined: Mon Nov 16, 2009 4:41 pm

Vertical and horizontal Alignment in Table Cells with Image

Post by crobar »

Hi,

I have a table which contains images (tikzpicture) in one column. I would like the first column to have text centred vertically and horizontally. I would like the second column to have text left justified and centred vertically. I would like the third column to contain a small image centred vertically and horizontally. The final two columns should both be left justified and aligned at the top of the cell.

The closest I have come to this is with the code below:

Code: Select all

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{array}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{m{2cm} p{2cm} m{3cm} p{3cm} p{3cm}} 
		\toprule 
			\multicolumn{1}{c}{Header 1} & 
			\multicolumn{1}{c}{Header 2} & 
			\multicolumn{1}{c}{Header 3} & 
			\multicolumn{1}{c}{Header 4} & 
			\multicolumn{1}{c}{Header 5} \\ 
    \midrule
			Short Text & 	
			Slightly Longer Text & 
			    \begin{tikzpicture}[baseline={($(current bounding box.center)+(0,-0.5ex)$)}]
		          % Draw beam and end lines
		          \draw (-1.5,-0.75) rectangle (1.5,0.75) ;
		          \useasboundingbox (current bounding box.north west) ++(0,1ex) (current bounding box.south east) ++(0,-1ex);
		      \end{tikzpicture}
		  & 
		  \raisebox{0.6cm}{\parbox[t]{3cm}{Some text that extends onto more than one line as there's plenty of it.}} & 
		  \raisebox{0.6cm}{\parbox[t]{3cm}{Some text that extends onto more than one line as there's plenty of it. Some text that extends onto more than one line as there's plenty of it.}} \\
			Short Text	& 
			Slightly Longer Text & 
			    \begin{tikzpicture}[baseline={($(current bounding box.center)+(0,-0.5ex)$)}]
		          % Draw beam and end lines
		          \draw (-1.5,-0.75) rectangle (1.5,0.75) ;
		          \useasboundingbox (current bounding box.north west) ++(0,1ex) (current bounding box.south east) ++(0,-1ex);
		      \end{tikzpicture}
		  & 
		  \raisebox{0.4cm}{\parbox[t]{3cm}{Some text that extends onto more than one line as there's plenty of it.}} & 
		  \raisebox{0.4cm}{\parbox[t]{3cm}{Some text that extends onto more than one line as there's plenty of it. Some text that extends onto more than one line as there's plenty of it.}} \\
			Short Text & Slightly Longer Text & Short Text & Short Text & \\
			Short Text & Slightly Longer Text & Short Text & Short Text & \\
    \bottomrule 
\end{tabular}

\end{document}
I can manually fix the alignment of every cell individually, but I really want to have it happen automatically, so I can change the font size etc in future without screwing it up. How do I do this? Using the 'm' or 'b' column specifiers does not seem to have any effect whatsoever.

Thanks!
Last edited by crobar on Wed Nov 02, 2011 11:42 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

crobar
Posts: 12
Joined: Mon Nov 16, 2009 4:41 pm

Vertical and horizontal Alignment in Table Cells with Image

Post by crobar »

I've now had my question answered here.
Post Reply