7

I'm getting really frustrated. I want to enter the following table into my LaTeX document, but the first and third columns refuse to narrow so it is too wide. Can someone please tell me what I am doing wrong? If I can format it properly the table should fit to about half a page width. Thanks for any help.

\begin{table}
\begin{tabular}{|c p{3cm}|c p{2cm}|c p{5cm}|c p{2cm}|}
\hline
 & Gene & Protein & Disease \\
\hline
\multirow{3}{*}{Soluble lysozomal enzyme deficiencies} & CLN10 (CTSD)  & Cathepsin D & Congenital*, LINCL, JNCL, ANCL \\
& CLN1 & Palmitoyl protein thioesterase 1 (PPT1) & INCL*, LINCL, JNCL, ANCL \\
& CLN2 & Tripeptidyl peptidase 1 (TPP1) & LINCL, JNCL \\
\multirow{5}{*}{Non-enzyme deficiencies} & CLN3 & Transmembrane protein & JNCL* \\
& CLN5 & Soluble; lysosomal & LINCL, JNCL, ANCL \\
& CLN6 & Transmembrane protein; ER & LINCL, ANCL Kuf's Type A \\
& CLN7 (MSFD8) & Transmembrane protein; Endolysosomal transporter & LINCL \\
& CLN8 & Transmembrane protein; ER & LINCL \\
\hline
\end{tabular}
\caption{Classification of NCLs by CLN gene affected \cite{haltia} \\ *indicates main form of NCL associated with the gene}
\label{table1}
\end{table}
David Carlisle
  • 757,742

3 Answers3

4

The traditional left, centre and right aligned columns do not wrap. You should use a paragraph column in order to allow/force wrapping (or another package that allows additional column types, like tabularx's X-column, say).

The following modification to your table uses

  • tabularx to have adjustable width columns (X types) to fit within the remainder of \textwidth;
  • geometry to allow for more room on your page;
  • column formatting using the >{...} directive, supplied by the array package (loaded by tabularx).

enter image description here

\documentclass{article}
\usepackage[margin=15mm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{multirow}% http://ctan.org/pkg/multirow
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}
\begin{table}
  \begin{tabularx}
      {\textwidth}
      {|X p{3cm}|>{\raggedright\arraybackslash}X >{\raggedright\arraybackslash}p{2cm}|}
    \hline
     & Gene & Protein & Disease \\
    \hline
    \multirow{3}{*}{Soluble lysozomal enzyme deficiencies} & CLN10 (CTSD)  & Cathepsin D & Congenital*, LINCL, JNCL, ANCL \\
     & CLN1 & Palmitoyl protein thioesterase 1 (PPT1) & INCL*, LINCL, JNCL, ANCL \\
     & CLN2 & Tripeptidyl peptidase 1 (TPP1) & LINCL, JNCL \\
    \multirow{5}{*}{Non-enzyme deficiencies} & CLN3 & Transmembrane protein & JNCL* \\
     & CLN5 & Soluble; lysosomal & LINCL, JNCL, ANCL \\
     & CLN6 & Transmembrane protein; ER & LINCL, ANCL Kuf's Type A \\
     & CLN7 (MSFD8) & Transmembrane protein; Endolysosomal transporter & LINCL \\
     & CLN8 & Transmembrane protein; ER & LINCL \\
    \hline
  \end{tabularx}
  \caption{Classification of NCLs by CLN gene affected indicates main form of NCL associated with the gene}
  \label{table1}
\end{table}
\end{document}

Since I'm unfamiliar with the exact usage/context, you may need to adjust your \multirow specification.

Moriambar
  • 11,466
Werner
  • 603,163
4

I recommend the tabu* package for easy control of variable-width columns. In the definition X[4,l] which I have chosen for your first column, the relative width of the column is 4 (i.e. it is twice as wide as the second column), and cell alignment is left**. You can adjust the table width as desired by replacing to \textwidth with e.g. to 10cm.

In addition, I've inserted the tabular into a ThreePartTable environment to allow for table notes (footnotes), and increased \arraystretch to achieve a more pleasant line spacing. You might want to consider the booktabs package for additional style recommendations.

enter image description here

\documentclass{article}
\usepackage{tabu}
\usepackage{threeparttablex}
\renewcommand{\arraystretch}{1.5}

\begin{document}

\begin{table}
\begin{ThreePartTable}
\begin{tabu} to \textwidth {|   X[4,l] 
                                X[2,l] 
                                X[3,l]<{\strut} 
                                X[3,l]<{\strut}
                            |}
    \hline
     & Gene & Protein & Disease \\
\hline
    Soluble lysozomal enzyme deficiencies & CLN10 (CTSD)  & Cathepsin D & Congenital\tnote{*}, LINCL, JNCL, ANCL \\
     & CLN1 & Palmitoyl protein thioesterase 1 (PPT1) & INCL\tnote{*}, LINCL, JNCL, ANCL \\
     & CLN2 & Tripeptidyl peptidase 1 (TPP1) & LINCL, JNCL \\\hline
    Non-enzyme deficiencies & CLN3 & Transmembrane protein & JNCL\tnote{*} \\
     & CLN5 & Soluble; lysosomal & LINCL, JNCL, ANCL \\
     & CLN6 & Transmembrane protein; ER & LINCL, ANCL Kuf's Type A \\
     & CLN7 (MSFD8) & Transmembrane protein; Endolysosomal transporter & LINCL \\
     & CLN8 & Transmembrane protein; ER & LINCL \\
    \hline
\end{tabu}
\begin{tablenotes}
    \item[*] indicates main form of NCL associated with the gene
\end{tablenotes}
\caption{Classification of NCLs by CLN gene affected}
\label{table1}
\end{ThreePartTable}
\end{table} 

\end{document}

*According to my knowledge, you cannot use \multirow with tabu, however if my answer is close to what you want to achieve, that doesn't seem to be a restriction.

**A\strut needs to be inserted in columns that contain cells determining the row height to prevent incorrect spacing.

dgs
  • 2,741
  • In my opinion there is rarely need for \multirow; I'd say that shifting down the entries in the first column of this table hinders its readability, rather than enhancing it. – egreg May 31 '12 at 10:03
  • Concerning the readability of vertically ill-aligned cells, I completely agree. A (vertically top-aligned) \multirow or possibly an alternative means of row spanning would in my opinion be adequate here if the first-column entries were sufficiently long to determine the first row's height. – dgs May 31 '12 at 10:27
2

Since the table contains just four columns and three of the four columns would appear to require automatic line breaking in order to keep the table from becoming too wide, it's not clear what you're trying to achieve by specifying the table to have eight columns:

\begin{tabular}{|c p{3cm}|c p{2cm}|c p{5cm}|c p{2cm}|}

The four c-type columns are causing nothing but trouble. Omit them, and things will start to look to be on track.

To make further progress, I suggest you switch to a tabularx environment, set the table's target width to \textwidth, and apply a modified version of the X column type to columns 2, 3, and 4. I would also omit the \multicolumn wrappers. Optionally, get rid of the vertical rules -- trust me, they won't be missed -- and use macros of the booktabs package for well-spaced horizontal rules.

enter image description here

\documentclass{article}
\usepackage{tabularx,ragged2e,booktabs,amsmath}
\newcolumntype{L}[1]{>{\RaggedRight}p{#1}}
\newcolumntype{Z}{>{\RaggedRight}X}
\usepackage[flushleft]{threeparttable}

\hyphenation{endo-lyso-somal pep-tid-ase thio-ester-ase} \newcommand\mytab[1]{\smash[b]{% \begin{tabular}[t]{@{}p{\hsize}@{}} #1 \end{tabular}}}

\begin{document}

\begin{table} \setlength\extrarowheight{2pt} \setlength\tabcolsep{4pt} \begin{threeparttable} \begin{tabularx}{\textwidth}{@{} L{2.25cm} l Z Z @{}} \toprule & Gene & Protein & Disease \ \midrule \mytab{Soluble lysosomal enzyme deficiencies} & CLN10 (CTSD) & Cathepsin D & Congenital\tnote{}, LINCL, JNCL, ANCL \ & CLN1 & Palmitoyl protein thioesterase 1 (PPT1) & INCL\tnote{}, LINCL, JNCL, ANCL \ & CLN2 & Tripeptidyl peptidase 1 (TPP1) & LINCL, JNCL \ \addlinespace Non-enzyme deficiencies & CLN3 & Transmembrane protein & JNCL\tnote{*} \ & CLN5 & Soluble; lysosomal & LINCL, JNCL, ANCL \ & CLN6 & Transmembrane protein; ER & LINCL, ANCL Kuf's Type A \ & CLN7 (MSFD8) & Transmembrane protein; Endolysosomal transporter & LINCL \ & CLN8 & Transmembrane protein; ER & LINCL \ \bottomrule \end{tabularx}

\smallskip \begin{tablenotes} \small \item[*]indicates main form of NCL associated with the gene \end{tablenotes}

\caption{Classification of NCLs by CLN gene affected \cite{haltia} } \label{table1} \end{threeparttable} \end{table}

\end{document}

Mico
  • 506,678