3

Hi Im having some trouble aligning the text in the second column of a two column table. The first column the text aligns the way i want but the seconds columns text is not positioning properly.

\begin{table}[h]
\begin{center}
\begin{tabular}{ |m{7cm}|m{6cm}|}\hline
PHP & Hypertext Preprocessor \\[2ex] \hline
MySQL & Structured Query Language \\[2ex] \hline
HTML & Hypertext Preprocessor \\[2ex] \hline
JQUERY & JavaScript library \\[2ex] \hline
AJAX & Asynchronous JavaScript and XML \\[2ex] \hline
GUI & Graphical user interface \\[2ex] \hline
JavaScript & Hypertext Preprocessor \\[2ex] \hline
URL & Uniform resource locator \\[2ex] \hline
API & Application programming interface \\[2ex] \hline

\end{tabular}
\end{center}
\end{table}\newpage

Result

any help would be appreciated

lockstep
  • 250,273
  • unrelated to your problem but using [h] on its own is essentially an input error: latex will change it to [ht] to give itself a chance but still disallowing p floats makes it much more likely that the float goes to the end of the document. – David Carlisle Dec 09 '12 at 18:17

2 Answers2

6

I assume that your "not positioning properly" problem is that the text in the second column is not vertically centered in the cell. Perhaps this is the reason for using the m column type? Since in your case each cell is short enough to fit in a single line, there is no reason to use m type. I guess that what you are trying to do is to have more vertical space inside the cells.

If this is the case, you can get the desired effect by redefining \arraystretch. The following MWE shows you how.

\documentclass{article}
\usepackage{array}
\begin{document}
\begin{table}
\renewcommand{\arraystretch}{1.5}
\centering
\begin{tabular}{|l|l|}\hline
PHP & Hypertext Preprocessor \\\hline
MySQL & Structured Query Language \\\hline
HTML & Hypertext Preprocessor \\\hline
JQUERY & JavaScript library \\\hline
AJAX & Asynchronous JavaScript and XML \\\hline
GUI & Graphical user interface \\ \hline
JavaScript & Hypertext Preprocessor \\ \hline
URL & Uniform resource locator \\ \hline
API & Application programming interface \\ \hline
\end{tabular}
\end{table}
\end{document}

Result

EDIT: As suggested by cmhughes in a comment, I also removed the center environment and used \centering command. More info at Should I use center or centering for figures and tables?

JLDiaz
  • 55,732
1

The problem is the alignment. So what does @{}m{0pt}@{} stand for? @{} removes the empty space usually placed to separate the columns; hence having one on the right and left of m{0pt} creates non of those extra spaces. Notice that we do not have | after @{}m{0pt}@{} since we do not want the vertical rule of the column. Now the m{0pt} means that the column width is of zero length and thus non-existent. Essentially, what we have done is a phantom column just to help with the alignment.

The following should help in your ordeal:

enter image description here

\documentclass[letterpaper]{article}
\usepackage{array}
\begin{document}

\begin{table}[h]
\begin{center}
\begin{tabular}{|m{7cm}|m{6cm}|@{}m{0pt}@{}}
\hline
PHP & Hypertext Preprocessor & \\[2ex] \hline
MySQL & Structured Query Language & \\[2ex] \hline
HTML & Hypertext Preprocessor & \\[2ex] \hline
JQUERY & JavaScript library & \\[2ex] \hline
AJAX & Asynchronous JavaScript and XML & \\[2ex] \hline
GUI & Graphical user interface & \\[2ex] \hline
JavaScript & Hypertext Preprocessor & \\[2ex] \hline
URL & Uniform resource locator & \\[2ex] \hline
API & Application programming interface & \\[2ex] \hline
\end{tabular}
\end{center}
\end{table}

\end{document}
azetina
  • 28,884