TeXnik - Tips TeX and LaTeX


Welcome to the TeXnik website (under construction)

Tables/Arrays
TUG logo

Main page

Index
UK FAQ
Documentation
Software
CTAN
Search CTAN:

Statistics

Google c.t.t.

Google d.c.t.t.

 


 


@ symbol | 
A arraycolsep | 
B Boxed Line or Column in an Array | 
C caption (Problems) |  Caption in Longtable |  Cases without math |  Centered columns with a fixed width |  colortbl package (colored cells) |  Column separation | 
D Dashed lines in tables |  dcolumn -- Decimal columns |  Dynamical Tables | 
E Examples |  Excel tabels | 
F Figure and Text and vertical alignment |  Floatflt |  Float placement |  fontsize tablewide |  footnotes in tables |  Fractions in Tables | 
G
H Header/Footer and tables |  Height of the Rows |  Horizontal space in tables | 
I Importing Excel tabels | 
J
K
L Lineheight in arrays/tables |  Longtable |  LTX tabulars | 
M Mathsf in a table |  Multirow | 
N  | 
O Overlays | 
P parbox with table |  Placement of Floats | 
Q
R Raggedright lines |  Rotating Tabulars |  Rowheight in arrays/tables |  Row style | 
S Shaded Parts |  Sideways Tabulars | 
T tabcolsep |  Table and figure side by side |  Tables side by side |  Tables - vertical space |  tabular* Example |  tabularx |  Text and Figure and vertical alignment |  Textline - behind table |  Text flows around Table | 
U  | 
V Variable Number of Rows |  Vertical Lines (width) |  Vertical space in arrays/tables |  Vertical spacing for Figure and Text |  Vertically multicols | 
W Width of a table |  Width of Vertical Lines | 
X
Y
Z Zeilenhöhe in arrays/tables  | 
Available Packages on CTAN
array
autotab
blkarray
booktabs
cellular
colortab
colortbl
dcolumn
delimtxt
easytable
Excel-To-LaTeX
ftcap
hhline
longtable
ltablex
ltxtable
multirow
rccol
shadbox
stabular
supertabular
tabularx
tap
threeparttable
xl2latex
xtab


@-symbol

Between two colums of a tabular/array LaTeX inserts two times the space \tabcolsep / \arraycolsep. One time before and one time after the optional vertical line. This additional space can be overwritten with the @{} operator. Its argument can hold any command and can be empty, which is the same than a zero width.


tabularx

To get a tabular with a specific width, e.g. the textwidth, you can use package tabularx. For an example go here. There exists also a longtable version of tabularx, the package ltablex. In the preamble write
\usepackage{ltablex}\keepXColumns
For the columns which widths should be set by the package choose the column type X.

In case of a very small last column choose
\newcolumntype{Y}{>{\RaggedRight}X}
Remember that in those columns \\ ends the column line not the tabular line, which is possible with \tabularnewline.
Dynamical TablesExample
Creating Tables with a command like
\dyntable{5}
is possible with the following stuff in the preamble:
\makeatletter
\newcommand*{\InitToks}{\toks@={}}
\newcommand{\AddToks}[1]{%
  \toks@=\expandafter{\the\toks@ #1}}
\newcommand*{\PrintToks}{\the\toks@}

\newcommand*{\dyntable}[1]{%
 \begingroup
 \InitToks
 \AddToks{\begin{tabular}{c}}%
 \count@=0 %
 \loop\ifnum\count@<#1\relax
  \advance\count@ by 1 %
  \expandafter\AddToks\expandafter{%
   \the\count@. Row \tabularnewline}%
 \repeat
 \AddToks{\end{tabular}}%
 \PrintToks
 \endgroup}
\makeatother
It produces the output:
1. Row
2. Row
3. Row
4. Row
5. Row
dynamic0.png


Fractions in Tables
Fractions look extremely ugly in tables, because there is no space over under. Write the following code in the preamble and then use $\tabfrac{...}{...}$ when writing math fractions in tables.
\newcommand{\tabfrac}[2]{%
	\setlength{\fboxrule}{0pt}%
	\fbox{$\frac{#1}{#2}$}%
}
This writes a fbox without a rule but with the fboxsep. For another example look here.


Raggedright Rows
When having p{..} columns which are left-, rightaligned or centered, then a \\ at the end of the row ends the textline but not the tabularline. In this case still use \tabularnewline. F.ex.:


Vertical space between rows
Write before your table/array f.ex.:
\renewcommand{\arraystretch}{1.5}
You can choose any other factor for the spacing.

For eqnarray (also all amsmath special environments) use

\addtolength{\jot}{5pt}


Column separation
\tabcolsep is the half space between two cells in tables. There are two ways to change this value:
\addtolength{\tabcolsep}{-1mm}
\setlength{\tabcolsep}{3mm}
The values are only examples. With the first one you are able to reset the value behind a table with the positive value or viceversa.
Possible are all valid units, like pt, cm,...
The commands may be in LaTeX preamble or anywhere in the text.
This command is not possible in the array environment!

it's also possible to turn off the separation when you insert as an argument @{}c|c@{} (as an example for a 2*2 table with no borders on the left and the right)

On the other hand you can insert any character as a separation, e.g. a "=". The following code defines this character as column separator and defines a macro specialLine which has no separator:


parbox as table
To define a parbox we need a width. With the tabular environment we can define a "dynamic" parbox:

  • insert a 1x1 tabular with \begin{tabular}{@{}c@{}}.
  • Now you can write anything into the table and the "parbox" gets the width of the longest line.


    Importing Excel Tables
    try package excel2latex, available at CTAN.

    Header/Footer and tables
    It is possible to put tables in the header or footer. For example a table in the header. In Latex preamble

    \usepackage{fancyhdr}
    In Latex Preamble or in the text:
    \newcommand\myTable{%
    \begin{tabular}{|c|c|}\hline
    a & b \\\hline
    c & d\\\hline
    \end{tabular}%
    }
    \fancyhead[LE,LO]{\myTable\hfill\thepage}
    gives the following table in the header
    -----
    |a|b|
    |c|d|
    -----


    tablewide fontsize
    for changing the font for the whole table write just before the table (outside)
    \scriptsize
    or any other fontsize. Just behind the table (outside)
    \normalsize
    Or alternative when you want all tables with the font size \tiny


    Footnotes in tables
  • in the table write in tex (red) \footnotemark
  • outside of the table or the floating table (all in texmode - red)
    \addtocounter{footnote}{-(n-1)}
    \footnotetext{... the footnotetext ...}
    \stepcounter{footnote}\footnotetext{... the next footnotetext ...}
    ...
    
    n is the number of footnotes in your table, e.g. 3, than you have to write \addtocounter{footnote}{-2}.This command is not necessary if there is only one footnote.


    Table - Vertical Space
    Same height for all rows
    this works for tables and arrays too!
    In latex preamble or anywhere else:
    \renewcommand\arraystretch{MyValue}% (MyValue=1.0 is for standard spacing)
    Different height for single rows
    Write in latex preamble:
    \newlength{\myVSpace}% the height of the box
    \setlength{\myVSpace}{1ex}% the default, 
    \newcommand\xstrut{\raisebox{-.5\myVSpace}% symmetric behaviour, 
      {\rule{0pt}{\myVSpace}}%
    }
    and than once in every table- or arrayline  
    \xstrut
    
    \xstrut defines an unvisible box with the specific height. You can change the height with
    \addtolength{\myVSpace}{1cm}

    Automatic Lineheight
    With package tabls.


    Mathsf in tables
    It needs some tricky code to get a table column in sf mode:

    mathsf.png

    local time: Tue Dec 10 16:24:26 CET 2019 ; file is: 170.295173611111 days old
    contact webmaster _at_ TeXnik.de