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?

8
  • Welcome to TeX.SE! I'm not sure I understand what you mean by "middle vertical align[ment]". Please elaborate.
    – Mico
    Jun 17, 2015 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, 2015 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 have top' alignment. \\\hline\end{tabular}`
    – LaRiFaRi
    Jun 18, 2015 at 7: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, 2015 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, 2015 at 16:00

1 Answer 1

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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .