# LaTeX code for Tables

\documentclass[a4paper,11pt]{article}
\usepackage{ulem}
\usepackage{a4wide}
\usepackage[dvipsnames,svgnames]{xcolor}
\usepackage[pdftex]{graphicx}

\usepackage{hyperref}
% commands generated by html2latex

\begin{document}

Tables may be authored in wiki pages using either HTML table elements directly, or using wikicode formatting to define the table. HTML table elements and their use are well described on various web pages and will not be discussed here. The benefit of wikicode is that the table is constructed of character symbols which tend to make it easier to perceive the table structure in the article editing view compared to HTML table elements.

As a general rule, it is best to avoid using a table unless you need one. Table markup often complicates page editing.
\begin{tabular}

\subsection{Contents}
\begin{itemize}
\begin{itemize}
\begin{itemize}
\end{itemize}
\item \hyperlink{With_HTML_attributes_and_CSS_styles}{2.4With HTML attributes and CSS styles}
\begin{itemize}
\end{itemize}
\end{itemize}
\begin{itemize}
\begin{itemize}
\end{itemize}
\begin{itemize}
\end{itemize}
\end{itemize}
\begin{itemize}
\end{itemize}
\begin{itemize}
\end{itemize}
\end{itemize}
\end{tabular}\hypertarget{Wiki_table_markup_summary}{}

\subsection{ Wiki table markup summary }
\begin{tabular}\hline
\{|  & \textbf{table start} \\
\hline
|+  &  table \textbf{caption,}\textit{optional;} only between \textbf{table start} and first \textbf{table row} \\
\hline
|-  & \textbf{table row,}\textit{optional on first row} -- wiki engine assumes the first row \\
\hline
!   & \textbf{table header} cell, \textit{optional.} Consecutive \textbf{table header} cells may be added on same line separated by double marks (!!) or start on new lines, each with its own single mark (!). \\
\hline
|   & \textbf{table data} cell, \textit{required!} Consecutive \textbf{table data} cells may be added on same line separated by double marks (||) or start on new lines, each with its own single mark (|). \\
\hline
|\}  & \textbf{table end} \\
\hline

\end{tabular}
\begin{itemize}
\item The above marks must \textbf{start on a new line} except the double || and\nolinebreak!! for optionally adding consecutive cells to a line.
\item \textbf{XHTML attributes.} Each mark, except table end, optionally accepts one or more XHTML attributes. Attributes must be on the same line as the mark. Separate attributes from each other with a single space.
\begin{itemize}
\item Cells and caption (| or ||, ! or !!, and |+) hold content. So separate any attributes from content with a single pipe (|). Cell content may follow on same line or on following lines.
\item Table and row marks (\{| and |-) do not directly hold content. Do \textit{not} add pipe (|) after their optional attributes. If you erroneously add a pipe after attributes for the table mark or row mark the parser will delete it \textit{and} your final attribute if it was touching the erroneous pipe!
\end{itemize}
\item \textbf{Content} may (a) follow its cell mark on the same line after any optional XHTML attributes or (b) on lines below the cell mark. Content that uses wiki markup that itself needs to start on a new line, such as lists, headers, or nested tables, must of course be on its own new line.
\end{itemize}\hypertarget{Simple_table}{}

\subsection{Simple table}\hypertarget{Plain}{}

\subsubsection{Plain}

The following table lacks borders and good spacing but shows the simplest wiki markup table structure
\begin{tabular}
\begin{tabular} \\
& Orange & Apple \\
Butter & Ice cream
\end{tabular}
\begin{verbatim}

{|
|Orange
|Apple
|-
|Pie
|-
|Butter
|Ice cream
|}
\end{verbatim}
\end{tabular}\hypertarget{Alternative}{}

\subsubsection{Alternative}

For more table-ish looking wiki markup cells can be listed on one line separated by ||. This does not scale well for longer cell content such as paragraphs. It works well for short bits of content however, such as our example table.

Extra spaces within cells in the wiki markup can be added, as I have done in the wiki markup below, to make the wiki markup itself look better but they do not affect the actual table rendering.

HTML attributes can be added to tables on this page but have been left out of the following example for simplicity.
\begin{tabular}
\begin{tabular} \\
&   Orange     &    Apple    &    more \\
Bread     &    Pie      &    more \\
Butter    &  Ice cream  &   and more
\end{tabular}
\begin{verbatim}

{|
|  Orange    ||   Apple   ||   more
|-
|   Bread    ||   Pie     ||   more
|-
|   Butter   || Ice cream ||  and more
|}
\end{verbatim}
\end{tabular}\hypertarget{With_HTML_attributes}{}

\subsubsection{With HTML attributes}

\paragraph{border="1"}
\begin{tabular}
\begin{tabular}\hline
& Orange & Apple \\
\hline
\hline
Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

{| border="1"
|Orange
|Apple
|-
|Pie
|-
|Butter
|Ice cream
|}
\end{verbatim}
\end{tabular}\hypertarget{align.3D.22center.22_border.3D.221.22}{}

\paragraph{align="center" border="1"}
\begin{tabular}
\begin{tabular}\hline
& Orange & Apple \\
\hline
\hline
Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

{| align="center" border="1"
|Orange
|Apple
|-
|Pie
|-
|Butter
|Ice cream
|}
\end{verbatim}
\end{tabular}\hypertarget{Attributes_on_cells}{}

\paragraph{Attributes on cells }

You can put attributes on individual \textbf{cells.} Numbers for example may look better aligned right
\begin{tabular}
\begin{tabular}\hline
& Orange & Apple & 12,333.00 \\
\hline
Bread & Pie & 500.00 \\
\hline
Butter & Ice cream & 1.00 \\
\hline

\end{tabular}
\begin{verbatim}

{| border="1"
|Orange
|Apple
|align="right"|12,333.00
|-
|Pie
|align="right"|500.00
|-
|Butter
|Ice cream
|align="right"|1.00
|}
\end{verbatim}
\end{tabular}\hypertarget{Attributes_on_rows}{}

\paragraph{Attributes on rows}

You can put attributes on individual \textbf{rows,} too.
\begin{tabular}
\begin{tabular}\hline
& Orange & Apple & 12,333.00 \\
\hline
Bread & Pie & 500.00 \\
\hline
Butter & Ice cream & 1.00 \\
\hline

\end{tabular}
\begin{verbatim}

{| border="1"
|Orange
|Apple
|align="right"|12,333.00
|-
|Pie
|align="right"|500.00
|- style="font-style:italic;color:green;"
|Butter
|Ice cream
|align="right"|1.00
|}
\end{verbatim}
\end{tabular}\hypertarget{cellspacing.3D.220.22_border.3D.221.22}{}

\paragraph{cellspacing="0" border="1"}
\begin{tabular}
\begin{tabular}\hline
& Orange & Apple \\
\hline
\hline
Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

{| cellspacing="0" border="1"
|Orange
|Apple
|-
|Pie
|-
|Butter
|Ice cream
|}
\end{verbatim}

\begin{tabular}
\begin{tabular}\hline
& Orange & Apple \\
\hline
\hline
Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

|Orange
|Apple
|-
|Pie
|-
|Butter
|Ice cream
|}
\end{verbatim}
\end{tabular}\hypertarget{With_HTML_attributes_and_CSS_styles}{}

\subsubsection{With HTML attributes and CSS styles}

CSS style attributes can be added with or without other HTML attributes\hypertarget{style.3D.22color:green.3Bbackground-color:.23ffffcc.3B.22_cellpadding.3D.2220.22_cellspacing.3D.220.22_border.3D.221.22}{}

\begin{tabular}
\begin{tabular}\hline
& Orange & Apple \\
\hline
\hline
Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

|Orange
|Apple
|-
|Pie
|-
|Butter
|Ice cream
|}
\end{verbatim}

\paragraph{Each column}
\begin{tabular}
\begin{tabular}\hline
& \textbf{Yummy} & \textbf{Yummier} \\
\hline
Orange & Apple \\
\hline
\hline
Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

!Yummy
!Yummier
|-
|Orange
|Apple
|-
|Pie
|-
|Butter
|Ice cream
|}
\end{verbatim}
\end{tabular}\hypertarget{Colspan.3D.222.22}{}

\paragraph{Colspan="2"}
\begin{tabular}
\begin{tabular}\hline
& \textbf{Yummies} \\
\hline
Orange & Apple \\
\hline
\hline
Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

! colspan="2"|Yummies
|-
|Orange
|Apple
|-
|Pie
|-
|Butter
|Ice cream
|}
\end{verbatim}

\paragraph{Default}
\begin{tabular}
\begin{tabular}\hline
& \textbf{Fruit} & Orange & Apple \\
\hline
\textbf{Dish} & Bread & Pie \\
\hline
\textbf{Complement} & Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

!Fruit
|Orange
|Apple
|-
!Dish
|Pie
|-
!Complement
|Butter
|Ice cream
|}
\end{verbatim}
\end{tabular}\hypertarget{Right_justify}{}

\paragraph{Right justify}

Right justified side headings can be done as follows
\begin{tabular}
\begin{tabular}\hline
& \textbf{Fruit} & Orange & Apple \\
\hline
\textbf{Dish} & Bread & Pie \\
\hline
\textbf{Complement} & Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

!align="right" |Fruit
|Orange
|Apple
|-
!align="right" |Dish
|Pie
|-
!align="right" |Complement
|Butter
|Ice cream
|}
\end{verbatim}
\end{tabular}\hypertarget{Caption}{}

\subsection{Caption}

A \textbf{table caption} can be added to the top of any table as follows
\begin{tabular}
\begin{tabular}\hline

% if you want to use \caption the tabular must be enclosed in
% table or figure environment
% \caption{Food complements}
& Orange & Apple \\
\hline
\hline
Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

|+Food complements
|-
|Orange
|Apple
|-
|Pie
|-
|Butter
|Ice cream
|}
\end{verbatim}
\end{tabular}

\textbf{Attributes} can be added to the caption as follows
\begin{tabular}
\begin{tabular}\hline

% if you want to use \caption the tabular must be enclosed in
% table or figure environment
% \caption{\textit{Food complements}}
& Orange & Apple \\
\hline
\hline
Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

|+align="bottom" style="color:#e76700;"|''Food complements''
|-
|Orange
|Apple
|-
|Pie
|-
|Butter
|Ice cream
|}
\end{verbatim}

\subsection{Table with H1, H2, H3 etc. headings}

HTML H1, H2, H3, H4 etc. headings can be created the standard wiki markup way with ==equal== signs and \textbf{must be on a line all by themselves} to work.

\textbf{Preview the whole table.} If you click on an edit tab for a heading \textit{within} a table, edit, and preview, the parent table will display erroneously broken because part of it will be missing.

\begin{tabular}
\begin{tabular}\hline
& \hypertarget{Yummiest}{}

\subsubsection{Yummiest} \\
\hline
Orange & Apple \\
\hline
\hline
Butter & Ice cream \\
\hline

\end{tabular}
\begin{verbatim}

|colspan="2"|
===Yummiest===
|-
|Orange
|Apple
|-
|Pie
|-
|Butter
|Ice cream
|}
\end{verbatim}
\end{tabular}\hypertarget{Caveat}{}

\subsection{Caveat}\hypertarget{Negative_numbers}{}

\subsubsection{Negative numbers}

Negative value minus sign can break your table (it may display missing some values) if you start a cell on a new line with a negative number or a parameter that evaluates to a negative number (|-6) because that is the wiki markup for table row, not table cell. To avoid this, insert a space before the value (| -6) or use in-line cell markup (||-6).