Monday, 27 January 2014

[Latex] A couple of tips about table

Table

Change the vertical space between caption and table

  • Include caption package
  • Use captionsetup
      \usepackage{caption}
      \captionsetup[table]{skip=10pt} % set the vertical space between caption and table

Change the space between rows in table

  • Define a newcommand \ra
      \newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}} % more space between rows in table
  • Use it in the beginning of the table
      \begin{table}[!hbpt]
          \caption{Example} \label{tab:exam}
          \centering
          \ra{1.3}
          \begin{tabular}{@{}lll@{}} %@{} remove the space to the vertical edge
          \end{tabular}
      \end{table}
  • For longtable, put it before \begin{longtable}
      \ra{1.4}
      \begin{longtable}[t]{@{}p{2cm}p{1cm}p{2.5cm}p{3cm}p{6.5cm}@{}}

Customize line width of tables

  • Include booktabs package
      \usepackage{booktabs} %table rules \toprule, \midrule, and \bottomrule
  • \toprule replaces first \hline
  • \bottomrule replaces last \hline
  • \midrule replaces other \hline
  • \cmidrule{2-3} replace \cline
  • Change default line width by, such as \toprule[1pt]

Example

\begin{tabular}{@{}lll@{}} %@{} remove the space to the vertical edge
    \toprule[1pt]
    Progression & Due Date & Status\\
    \midrule
    Submit & 30 Sep 2016 & WIP \\ \cmidrule{2-3}
    \bottomrule
\end{tabular}

Multi-pages and long table

Example

    \begin{longtable}[]{@{}p{0.7in}p{1.0in}p{1.5in}p{2.7in}@{}}
        \caption{$\Phi$ translation rules} \label{tab:phi_rule} \\
        \toprule
        & & & \\
        \midrule
        & & & \\
        \bottomrule
    \end{longtable}

Multi columns

  • Use \multicolumn

Example

    \midrule
     & \multicolumn{3}{p{5.5in}}{In order to identify the state space.} \\ \cmidrule{2-4}
    \midrule

Multi rows

  • Include multirow package
      \usepackage{multirow} %\multirow
  • Use \multirow command

Example

    \begin{tabular}{@{}p{1cm}p{4cm}p{2.8cm}p{0.7cm}p{5cm}@{}}
        \toprule
        Stage & Description & Deliverables & Status & Notes \\
        \midrule
        \multirow{2}{*}{Stage1} & \multirow{2}{*}{\parbox{4cm}{approach}} & Conference Paper & Done & \\
        & & Simple Translator & Done & Simple translator is ready \\
        \bottomrule
    \end{tabular}

Remove the space to the vertical edge

  • @{} remove the space to the vertical edge

For example

  • Remove left and right vertical edge
      \begin{tabular}{@{}p{1cm}p{4cm}p{2.8cm}p{0.7cm}p{5cm}@{}}

Text wrap in table cell

by p{} column specification

  • such as
      \begin{tabular}{@{}p{1cm}p{4cm}p{2.8cm}p{0.7cm}p{5cm}@{}}
          & & Simple Translator & Done & Simple translator is ready \\
          & & Simple \newline Translator & Done & Simple translator is ready \\
  • \newline command can be used to break the line

by \parbox{}

  • such as
      {\parbox{5.0in}{Some of expressions, operators and predicatesle}}

No comments :

Post a Comment