2

I have a need to create a table, I have shown a MWE, its producing the table with the text I want. I have two question relating to the attached image.

  1. How to change the height of cells.
  2. How to control the line so that it does not span across the table. my second column is 10cm and I want the line to travel only 2 cm

Sample code:

\documentclass[fleqn,12pt,a4paper]{article}
\usepackage{tabularx}
\usepackage{multicol}
\begin{document}

\begin{tabular}{p{2cm}|p{10cm}}
Heading & relavent text  \\
\hline
Alphabets & A B C D E F G .. .... .... ...  Z \\
\hline
Numbers & 1 2 3 .. .... .... .... 10 etc

\end{tabular}
\end{document}

enter image description here

David Carlisle
  • 757,742
Aku
  • 11,026
  • 1
    I suggest you use the booktabs package, turn Heading, Alphabets, and Numbers into bold face text, get rid of the vertical bars, and use \midrule instead of \hline. –  Sep 16 '12 at 17:34
  • Marc - even \midrule goes from one end to other. Nothing changed I could not produce anywhere close to the attached image. Also is there anyway to keep the vertical line – Aku Sep 16 '12 at 19:35
  • The command \cmidrule, which is provided by booktabs, should let you create partial rules. It's described in the booktabs manual. –  Sep 16 '12 at 19:50
  • @Aku What results from your code is not like the image you show. The line extends all along the cell width (which is set to 10cm, as you state in the argument to tabular). – egreg Sep 16 '12 at 19:50
  • @egreg - yes the hline or midrule line extends along all the cell width. – Aku Sep 16 '12 at 19:53
  • @Aku So, what's the question? If you want that it covers only up to the widest entry, don't declare the column as p, but as l. – egreg Sep 16 '12 at 19:56
  • I have only two columns, Second column is 10 cm however I want the line to travel only 2cm as shown in the image. l declaration or P its putting the line under entire column. – Aku Sep 16 '12 at 20:00
  • @Aku I still don't understand why. Could you make a "real" example? – egreg Sep 16 '12 at 23:32
  • For modifying cell spacing/padding, see Column padding in tables. – Werner Sep 17 '12 at 04:01

1 Answers1

5

I am guessing this is what you are looking for second part. I don't know how to change the height of the rows. Although I found a question where they talk about it.

\documentclass[fleqn,12pt,a4paper]{article}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{p{2cm}p{2cm}@{}p{8cm}}
    & & \\[-\normalbaselineskip]    % Required to get the cmidrule to work.
    Heading         & \multicolumn{2}{l}{relevant text} \\ \cmidrule{1-2}
    Alphabets       & \multicolumn{2}{l}{A B C D E F G .. .... .... ...  Z} \\ \cmidrule{1-2}
    Numbers         & \multicolumn{2}{l}{1 2 3 .. .... .... .... 10 etc}
\end{tabular}

\end{document}

There must be a better way than this.

Following on Harish's comment to use arraystretch you can do something like this,

\begingroup
    \renewcommand\arraystretch{2}
    \begin{tabular}{p{2cm}p{2cm}@{}p{8cm}}
        & & \\[-\normalbaselineskip]    % Required to get the cmidrule to work.
        Heading         & \multicolumn{2}{l}{relevant text} \\ \cmidrule{1-2}
        Alphabets   & \multicolumn{2}{l}{A B C D E F G .. .... .... ...  Z} \\ \cmidrule{1-2}
        Numbers         & \multicolumn{2}{l}{1 2 3 .. .... .... .... 10 etc}
    \end{tabular}
\endgroup

\begingroup and \endgroup ensure that other tables in the document are not affected.

mythealias
  • 3,621
  • The necessity for the "phantom line" is because otherwise all cells in the second and third columns are merged, so TeX treats them as if they were one; and this confuses the LaTeX mechanism for drawing lines across some columns only. I'd say \\[-\normalbaselineskip] rather than \\[-1em]. – egreg Sep 16 '12 at 23:31
  • You can use \usepackage{array} \renewcommand\arraystretch{2} to change the row height. –  Sep 16 '12 at 23:43