0

I want to andjust the width of columns at the same time as i adjust the row height. How can I adjust both parameters with the \newcolumntype{}{} macro?

I have created this type of column:

\newcolumntype{a}{>{\columncolor{classicrose}}p{8.5cm}} 

I tried \newcolumntype{a}{>{\columncolor{classicrose}}p{8.5cm} m{1cm}}, but it did not work.

Here is a complete example of a table:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{colortbl}
\usepackage{xcolor} 
\definecolor{classicrose}{rgb}{0.98, 0.8, 0.91}
\newcolumntype{a}{>{\columncolor{classicrose}}p{8.5cm}}

\begin{tabular}{|a|a|}
    \hline
    1238201 & 271991 \\
    \hline
    numbers! & more numbers!! \\
    \hline
    87282198212891 & many numbers! \\
    \hline
\end{tabular}

I want more horizontal space in each row between the text and the line (over and under). Now the row is so small that it almost "touches" the text.

Edit: Here's an example of how I would like the vertical row height to look (a bit exaggerated): enter image description here

2

More vertical space in cells you can obtain by use of the cellspace package:

\documentclass{article}
\usepackage{cellspace, tabularx}
    \setlength\cellspacetoplimit{20mm}    % <---
    \setlength\cellspacebottomlimit{20mm} % <---
\usepackage[table]{xcolor}
    \definecolor{classicrose}{rgb}{0.98, 0.8, 0.91}
    \newcolumntype{a}{>{\columncolor{classicrose}}S{X}}

\begin{document}
\begin{tabularx}{\linewidth}{|a|a|}
    \hline
    1238201 & 271991 \\
    \hline
    numbers! & more numbers!! \\
    \hline
    87282198212891 & many numbers! \\
    \hline
\end{tabularx}
\end{document}

which gives:

enter image description here

In above MWE is used tabularx because it enable simple automatic adoption the width of the table to the \textwidth (using p{8.5vm} at given page layout cause that table protrude out of page).

Of course, you can still stick with your column definition:

\newcolumntype{a}{>{\columncolor{classicrose}}S{p{8.5cm}}}
\begin{document}
\begin{tabular}{|a|a|}
...

and solve the spill-out out of the table page on some other way.

Edit: Now vertical spaces in cells are increased to 20mm as OP express his wish in comment.

6
  • cellspace is easiest solution, but tabularx is a bit presumptive. He may not want to use \linewidth. Nov 20 '19 at 5:06
  • @JohnKormylo,you may be right, see edited answer.
    – Zarko
    Nov 20 '19 at 5:20
  • Doesn't work with the \setlength. The vertical height of the row doesn't change...
    – Vebjorn
    Nov 20 '19 at 13:25
  • @Vebjorn,which \setlength? My MWE works as advertised. Vertical space in cells are increased for 5 pt above and below texts in cells.
    – Zarko
    Nov 20 '19 at 14:42
  • @Zarko I want more space. But when I adjust it to 10pt or 20mm I see no difference in the table (row height)...
    – Vebjorn
    Nov 20 '19 at 22:59

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.