2
\documentclass{article}    
\begin{document}

 \begin{center}
    \begin{tabular}{ | p{5cm} | p{5cm} | p{7cm} |}\hline

\centering{A} &     
\centering{B} &     
\centering{C} \\ \hline

\end{tabular} 
\end{center}

\end{document}

I am making an A4 document and I want the words in the first row of the table to be centered. Here I have omitted other rows. But errors occur and it seems that I can't use \centering for the last column. Why doesn't it work?

Nighty
  • 123
  • 5
  • Welcome to TeX.SE! I'm not sure I understand what you mean by "middle vertical align[ment]". Please elaborate. – Mico Jun 17 '15 at 16:24
  • @Mico : I mean 'paragraph column with text vertically aligned in the middle' (from wiki) and therefore i use the code m{5cm}. – Nighty Jun 17 '15 at 16:34
  • @LeeKM It should be \begin{tabular}{|m{2.8cm}|m{2.8cm}|m{5cm}|} \hline A & \multicolumn{1}{c|}{B} & C \\\hline A & B & I want the first two columns to have middle vertical align but the last column remains to havetop' alignment. \\hline\end{tabular}` – LaRiFaRi Jun 18 '15 at 07:31
  • @LaRiFaRi : thx for replying. Actually I want to keep the width of the columns as 5cm, 5cm and 7cm. Will this restriction prohibit me using \centering? – Nighty Jun 18 '15 at 11:45
  • 1
    If the table is supposed to be at least 17cm wide, it will likely not fit inside the text block (unless the paper size is unusually large and/or the margins are unusually narrow). – Mico Jun 18 '15 at 16:00
  • @Mico : in short, centering does not work since i insist i) using A4 paper and ii) having a 17cm-long-table? – Nighty Jun 18 '15 at 16:02
  • Well, if you set the margins to something like 5mm, centering will work... – Mico Jun 18 '15 at 16:05
  • @Mico : i see! i would appreciate that if you can show a simple example and put it as an answer! – Nighty Jun 18 '15 at 16:18

1 Answers1

1

With the width of the tabular exceeding 17cm, the margins have to be quite narrow if the material is supposed to fit inside the textblock. In the example below, the margins are set to 1cm. (Aside: rather than setting puny margins, I'd reduce the column widths in the tabular.)

enter image description here

\documentclass{article}    
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{lipsum}  % filler text
\begin{document}

\hrule %% just to illustrate width of text block

\begin{center}
\begin{tabular}{ | p{5cm} | p{5cm} | p{7cm} |}
\hline
\multicolumn{1}{|c}{A} & \multicolumn{1}{|c}{B} & \multicolumn{1}{|c|}{C} \\ 
\hline
\lipsum*[2] & \lipsum*[2] & \lipsum*[2] \\
\hline
\end{tabular} 
\end{center}

\end{document}
Mico
  • 506,678