Graphics, Figures & TablesAlignment problems in array environment

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
andersbongo
Posts: 3
Joined: Sat Sep 19, 2009 3:47 pm

Alignment problems in array environment

Post by andersbongo »

I'm trying to typeset a single-row two-column array (tabular) with a matrix in the first cell and a picture in the second cell. The code is as follows:

Code: Select all

\setlength{\unitlength}{1cm}
\begin{center}
	\begin{tabular}{cc}
		$c_e=\begin{pmatrix} -&3&4&2\\-&-&5&6\\-&-&-&12\\-&-&-&- \end{pmatrix}$
		& 
		\begin{picture}(4.5,4.5)

			\put(0.5,3.5){\circle*{0.2}}  % v_1
			\put(3.5,3.5){\circle*{0.2}}  % v_2
			\put(0.5,0.5){\circle*{0.2}}  % v_3
			\put(3.5,0.5){\circle*{0.2}}  % v_4

			\put(0.0,3.8){$v_1$}
			\put(3.7,3.8){$v_2$}
			\put(0.0,0.0){$v_3$}
			\put(3.7,0.0){$v_4$} 

			\put(0.5,3.5){\line(1,0){3}}    % v_1 > v_2
			\put(0.5,3.5){\line(0,-1){3}}   % v_1 > v_3
			\put(0.5,3.5){\line(1,-1){3}}   % v_1 > v_4
			\put(3.5,3.5){\line(-1,-1){3}}  % v_2 > v_3
			\put(3.5,3.5){\line(0,-1){3}}   % v_2 > v_4
			\put(0.5,0.5){\line(1,0){3}}    % v_3 > v_4

			\put(1.9,3.7){\scriptsize{3}}  % c(v_1,v_2)
			\put(0.2,1.9){\scriptsize{4}}  % c(v_1,v_3)
			\put(1.1,2.4){\scriptsize{2}}  % c(v_1,v_4)
			\put(2.8,2.4){\scriptsize{5}}  % c(v_2,v_3)
			\put(3.6,1.9){\scriptsize{6}}  % c(v_2,v_4)
			\put(1.8,0.1){\scriptsize{12}} % c(v_3,v_4)

		\end{picture}
	\end{tabular}
\end{center}
However, the matrix sits at the bottom of the first cell, even stretching the array to an unnecessary large height. The cells should be vertically center-aligned. Changing to the array environment does not seem to work, as doesn't enclosing the contents of the first cell in {}.

Any ideas?

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Alignment problems in array environment

Post by Stefan Kottwitz »

Hi andersbongo,

welcome to the board!
You could use \parbox inside the cell to encapsulate the picture environment:

Code: Select all

\parbox{3cm}{\begin{picture}(4.5,4.5) ... \end{picture}}
Stefan
LaTeX.org admin
andersbongo
Posts: 3
Joined: Sat Sep 19, 2009 3:47 pm

Re: Alignment problems in array environment

Post by andersbongo »

Thanks a bunch for the quick reply! It works like a charm (after adjusting from 3 to 4cm).

Could you perhaps explain what went wrong in my code?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Alignment problems in array environment

Post by Stefan Kottwitz »

The picture environment has been aligned at its bottom line, that's why the bottom line was aligned with c_e= and vertically centered to the matrix, that's why the content of the picture has been put above.

A parbox will be aligned at its center line by default, that's why I've used it. The alignment of a parbox can be changed further.

Stefan
LaTeX.org admin
Post Reply