3

I have this silly question that might look like a duplicate, but I still cannot get it to work... I have the following table, and I just need more vertical spacing at the top and bottom of the 3rd row... Adding [3cm] after the end of the row would give me more space at the bottom of the row, but what about the space at the top? Many thanks! MWE:

\documentclass{standalone}

\usepackage{pbox}

\begin{document}

\renewcommand{\arraystretch}{2}
\begin{tabular}{|c|c|c|c|c|}
    \cline{2-5}
        \multicolumn{1}{c|}{}
        & \textbf{group a}
        & \textbf{group b}
        & \textbf{group c}
        & \textbf{group d}\\
    \cline{1-5}
        \textbf{classif1}
        & A
        & B
        & A
        & B\\
    \cline{1-5}
        \textbf{classif2}
        & A
        & B
        & B
        & A\\
    \cline{1-5}
        \textbf{IDs}
        & \textit{\pbox{20cm}{ALK, APC,\\CDH1, EGFR,\\GPC3, HNF1A,\\MPL, PHOX2B,\\RET, TSHR}}
        & \textit{\pbox{20cm}{AXIN1, BRCA2,\\BUB1B, CDKN2A,\\ERCC2, ERCC4,\\FANCC, FANCE,\\FH, HRAS,\\MLH1, MSH6,\\NF1, PMS2,\\PRKAR1A, RB1,\\SBDS, SDHAF2,\\SDHB, SDHD,\\SMAD4, SMARCB1,\\STK11, SUFU,\\TP53, TSC1,\\XPA, XPC}}
        & \textit{\pbox{20cm}{ATM, BLM,\\BRCA1, BRIP1,\\CDC73, CDK4,\\CHEK2, CYLD,\\DDB2, DICER1,\\ERCC3, ERCC5,\\EXT1, EXT2,\\FANCA, FANCD2,\\FANCG, FLCN,\\MSH2, MUTYH,\\NF2, PALB2,\\PMS1, RECQL4,\\SDHC, SMARCE1,\\TSC2, VHL,\\WRN}}
        & \textit{\pbox{20cm}{BMPR1A, FANCF,\\KCNJ5, KIT,\\LMO1, MAX,\\MEN1, NBN,\\PRF1, PTCH1,\\PTEN, TERT,\\WT1}}\\[3cm]
    \cline{1-5}
        \textbf{Number}
        & 10
        & 28
        & 29
        & 13\\
    \cline{1-5}
\end{tabular}

\end{document}
  • Looks like a case for the ctan.org/pkg/cellspace package: "It is well known that high or deep cells tend to touch the \hlines of a tab­u­lar. This pack­age pro­vides a mod­i­fier S act­ing on usual col­umn types so that to en­sure a min­i­mal dis­tance that can be con­trolled through two pa­ram­e­ters \cellspace­to­plimit and \cellspace­bot­tom­limit." – Stephen Jan 26 '14 at 19:27
4

To force some additional vertical whitespace at the top and bottom of the cell in question, you could insert "struts" -- objects that have some height (and possibly depth) but no width, and hence are invisible. For instance, the instruction

\rule{0pt}{3cm}

will insert a "top strut" of height 3cm, and

\rule[-3cm]{0pt}{0pt}

will insert a "bottom strut" of depth 3cm.

To apply this to the table at hand, the cell in the "group c" column could be set up as

\textit{\pbox{20cm}{\rule{0pt}{3cm}ATM, BLM,\\BRCA1, BRIP1,\\CDC73, CDK4,\\CHEK2, CYLD,
  \\DDB2, DICER1,\\ERCC3, ERCC5,\\EXT1, EXT2,\\FANCA, FANCD2,\\FANCG, FLCN,
  \\MSH2, MUTYH,\\NF2, PALB2,\\PMS1, RECQL4,\\SDHC, SMARCE1,\\TSC2, VHL,
  \\WRN \rule[-3cm]{0pt}{0pt}}

For more on using struts in tables and on choosing strut height/depth settings that are typographically more appropriate than the 3cm example you gave, check out this posting (shameless self-citation alert!).

  • Cool! I have been playing around and got the aesthetics that I want. Though I'm still working with \renewcommand{\arraystretch}{2} along with the struts, is it ok, or the don't play well together? – DaniCee Jan 26 '14 at 19:44
  • As far as I know, inserting struts in no way interferes with resetting the \arraystretch parameter. – Mico Jan 26 '14 at 19:53
2

A first solution using the cellspace package, that defines the minimal distance between the text and the top or the bottom of the cell (\cellspacetoplimit & \cellspacebottomlimit):

\documentclass{standalone}

\usepackage{pbox, cellspace}
\cellspacetoplimit = 6pt\cellspacebottomlimit =6pt
\renewcommand{\arraystretch}{2}
\begin{document}

\begin{tabular}{>{\bfseries}c|*{4}{Sc|}}
\cline{2-5}
    \multicolumn{1}{c|}{}
    & \textbf{Class 1}
    & \textbf{Class 2}
    & \textbf{Class 3}
    & \textbf{Class 4}\\
\hline
   Penetrance
    & Tissue specific
    & Ubiquitous
    & Tissue specific
    & Ubiquitous\\
\hline
   Expression
    & Tissue specific
    & Ubiquitous
    & Ubiquitous
    & Tissue specific\\
\hline
   Genes
    & \textit{\pbox{20cm}{ALK, APC,\\CDH1, EGFR,\\GPC3, HNF1A,\\MPL, PHOX2B,\\RET, TSHR}}
    & \textit{\pbox{20cm}{AXIN1, BRCA2,\\BUB1B, CDKN2A,\\ERCC2, ERCC4,\\FANCC, FANCE,\\FH, HRAS,\\MLH1, MSH6,\\NF1, PMS2,\\PRKAR1A, RB1,\\SBDS, SDHAF2,\\SDHB, SDHD,\\SMAD4, SMARCB1,\\STK11, SUFU,\\TP53, TSC1,\\XPA, XPC}}
    & \textit{\pbox{20cm}{ATM, BLM,\\BRCA1, BRIP1,\\CDC73, CDK4,\\CHEK2, CYLD,\\DDB2, DICER1,\\ERCC3, ERCC5,\\EXT1, EXT2,\\FANCA, FANCD2,\\FANCG, FLCN,\\MSH2, MUTYH,\\NF2, PALB2,\\PMS1, RECQL4,\\SDHC, SMARCE1,\\TSC2, VHL,\\WRN}}
    & \textit{\pbox{20cm}{BMPR1A, FANCF,\\KCNJ5, KIT,\\LMO1, MAX,\\MEN1, NBN,\\PRF1, PTCH1,\\PTEN, TERT,\\WT1}}\\%
\hline
    Number
    & 10
    & 28
    & 29
    & 13\\
\hline
\end{tabular}

\end{document} 

Resulting in: enter image description here

Another solution uses the booktabs package and its \addlinespace command, but supposes no vertical lines (look better in the opinion of many):

\documentclass{standalone}

\usepackage{pbox, array, booktabs}
\renewcommand{\arraystretch}{2}

\begin{document}

\begin{tabular}{>{\bfseries}c*{4}{c}}
\cmidrule[\heavyrulewidth]{2-5}
    %\multicolumn{1}{c|}{}
    & \textbf{Class 1}
    & \textbf{Class 2}
    & \textbf{Class 3}
    & \textbf{Class 4}\\
\toprule
   Penetrance
    & Tissue specific
    & Ubiquitous
    & Tissue specific
    & Ubiquitous\\
\midrule
   Expression
    & Tissue specific
    & Ubiquitous
    & Ubiquitous
    & Tissue specific\\
\midrule\addlinespace
   Genes
    & \textit{\pbox{20cm}{ALK, APC,\\CDH1, EGFR,\\GPC3, HNF1A,\\MPL, PHOX2B,\\RET, TSHR}}
    & \textit{\pbox{20cm}{AXIN1, BRCA2,\\BUB1B, CDKN2A,\\ERCC2, ERCC4,\\FANCC, FANCE,\\FH, HRAS,\\MLH1, MSH6,\\NF1, PMS2,\\PRKAR1A, RB1,\\SBDS, SDHAF2,\\SDHB, SDHD,\\SMAD4, SMARCB1,\\STK11, SUFU,\\TP53, TSC1,\\XPA, XPC}}
    & \textit{\pbox{20cm}{ATM, BLM,\\BRCA1, BRIP1,\\CDC73, CDK4,\\CHEK2, CYLD,\\DDB2, DICER1,\\ERCC3, ERCC5,\\EXT1, EXT2,\\FANCA, FANCD2,\\FANCG, FLCN,\\MSH2, MUTYH,\\NF2, PALB2,\\PMS1, RECQL4,\\SDHC, SMARCE1,\\TSC2, VHL,\\WRN}}
    & \textit{\pbox{20cm}{BMPR1A, FANCF,\\KCNJ5, KIT,\\LMO1, MAX,\\MEN1, NBN,\\PRF1, PTCH1,\\PTEN, TERT,\\WT1}}\\%
\addlinespace\midrule
    Number
    & 10
    & 28
    & 29
    & 13\\
\bottomrule
\end{tabular}

\end{document}

It looks like this:

enter image description here

1

In tabulars special struts \@arstrut are inserted; they are normal struts, but multiplied with factor \arraystretch.

Because the \pboxes are so large, the automatically inserted struts do not have an effect. It would be better to add the strut at the first and last line of the lines in the \pbox. However, because of the large \arraystretch, the strut in the first line of \pbox should not have a depth and the strut in the last line should not have a height. This is achieved by the optional parameters of \raisebox{0pt} that allows the setting of the height and depth.

Further remarks:

  • The use of \arstrutDP, the strut with depth and zero height, in the last line of \pbox avoids the magic space value in the optional argument of \\[30cm].
  • Macro \pboxIDs calls \pbox with \itshape for its contents and adds the "half struts" to the first and last line.
\documentclass{standalone}

\usepackage{pbox}

\makeatletter
\newcommand*{\arstrutHT}{%
  \raisebox{0pt}[\height][0pt]{\@arstrut}%
}
\newcommand*{\arstrutDP}{%
  \raisebox{0pt}[0pt][\depth]{\@arstrut}%
}
\makeatother

\begin{document}

\renewcommand{\arraystretch}{2}
\newcommand*{\pboxIDs}[1]{%
  \pbox{20cm}{%
    \itshape
    \arstrutHT
    \ignorespaces
    #1%
    \unskip
    \arstrutDP
  }%
}
\begin{tabular}{|c|c|c|c|c|}
    \cline{2-5}
        \multicolumn{1}{c|}{}
        & \textbf{group a}   
        & \textbf{group b}   
        & \textbf{group c}   
        & \textbf{group d}\\ 
    \cline{1-5}
        \textbf{classif1}
        & A
        & B
        & A
        & B\\
    \cline{1-5}
        \textbf{classif2}
        & A
        & B
        & B
        & A\\
    \cline{1-5}
        \textbf{IDs}
        & \pboxIDs{ALK, APC,\\CDH1, EGFR,\\GPC3, HNF1A,\\MPL,
            PHOX2B,\\RET, TSHR}
        & \pboxIDs{AXIN1, BRCA2,\\BUB1B, CDKN2A,\\ERCC2,
            ERCC4,\\FANCC, FANCE,\\FH, HRAS,\\MLH1, MSH6,\\NF1,
            PMS2,\\PRKAR1A, RB1,\\SBDS, SDHAF2,\\SDHB, SDHD,\\SMAD4,
            SMARCB1,\\STK11, SUFU,\\TP53, TSC1,\\XPA, XPC}
        & \pboxIDs{ATM, BLM,\\BRCA1, BRIP1,\\CDC73, CDK4,\\CHEK2,
            CYLD,\\DDB2, DICER1,\\ERCC3, ERCC5,\\EXT1, EXT2,\\FANCA,
            FANCD2,\\FANCG, FLCN,\\MSH2, MUTYH,\\NF2, PALB2,\\PMS1, 
            RECQL4,\\SDHC, SMARCE1,\\TSC2, VHL,\\WRN}
        & \pboxIDs{BMPR1A, FANCF,\\KCNJ5, KIT,\\LMO1, MAX,\\MEN1,
            NBN,\\PRF1, PTCH1,\\PTEN, TERT,\\WT1}\\
    \cline{1-5}
        \textbf{Number}
        & 10
        & 28
        & 29
        & 13\\
    \cline{1-5}
\end{tabular}

\end{document}

Result

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