Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
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. –  Marc van Dongen 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. –  Marc van Dongen 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

1 Answer 1

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.

share|improve this answer
    
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
    
@egreg Thanks, I have modified the answer. –  mythealias Sep 16 '12 at 23:41
    
You can use \usepackage{array} \renewcommand\arraystretch{2} to change the row height. –  Harish Kumar Sep 16 '12 at 23:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.