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

  • 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. – user10274 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. – user10274 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
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.

  • 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. – user11232 Sep 16 '12 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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