Graphics, Figures & TablesMultiple Rows in Table Headers

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Multiple Rows in Table Headers

Post by sw3quant »

hello.

my MWE is:

Code: Select all

\begin{center}
\captionof{table}{\bf CME GLOBEX Interest Rate Futures.}
\tiny
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}
  \hline
  {\bf Name} & {\bf GLOBEX Ticker} & {\bf tickdata.com Ticker} & {\bf Bloomberg Ticker} & {\bf Daily Data Start Date} & {\bf Tick Size} & {\bf Tick Value  (\$)} &{\bf Contract Size (\$)} &{\bf Value/Point} &{\bf Quoting Spec.} & {\bf Int. Margin (\$)} & {\bf ADV (lots)} \\
  \hline \hline
  3M EURO\$ & GE & ED & ED1 Comdty & 01/01/1950 & 0.005      & 12.5 & 1,000,000 & 2,500 & 3 &       1,013     & 2,002,314 \\
  2Yr       & ZT & TU & TU1 Comdty & 01/01/1950 & 0.0078125 & 15.625 & 200,000 & 2,000 & 128ths &   810       & 238,396 \\
  5Yr       & ZF & FV & FV1 Comdty & 01/01/1950 & 0.0078125 & 7.8125 & 100,000 & 1,000 & 128ths &   1,080     & 577,484 \\
  10Yr      & ZN & TY & TY1 Comdty & 01/01/1950 & 0.015625 & 15.625 & 100,000 & 1,000 & 64ths &     1,890     & 1,101,934 \\
  30Yr      & ZB & US & US1 Comdty & 01/01/1950 & 0.03125  & 31.25 & 100,000 & 1,000 & 64ths &      3,375     & 321,724 \\
  \hline
\end{tabular}
\label{irDataTable}
%\vspace{0.1cm}
\end{center}
\normalsize
when I go to print this to PDF in A4 I see that its wider than the page due to long headers. Thus I wish to put the headers on two lines.

I have tried all the usual approaches (e.g. \parbox[c]{1.5cm}{tickdata.com Ticker}) but they all seem to skew the text off-center/ require to specify box size etc, which I am sure is incorrect.

What would a latex expert advise?

Thank you.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

Multiple Rows in Table Headers

Post by Stefan Kottwitz »

You could use p columns, instead of c, or just p headers. In general, for every formatting which you repeat, define a macro. So it's much easier to make changes. For example:

Code: Select all

\usepackage{array}
\newcommand{\head}[2]{\multicolumn{1}{>{\centering\arraybackslash}p{#1}}{\textbf{#2}}}
and in the table just write

Code: Select all

\head{1.5cm}{tickdata.com Ticker}
and similar for the other header entries.

\bf is an obsolete command, use \bfseries instead, or \textbf{...}. \normalsize is not necessary, since the effect of \tiny is limited by the center environment.

The table is hardly readable. I strongly recommend to use booktabs, and to remove vertical lines, I would use just horizontal lines in such tables.

I expect this table to be read row by row, not column by column. Or would you read the "Daily Data Start Date" column from up to down? Because the column is a vertical block, without horizontal lines. I would expect it the other way round. Vertical lines should not block the horizontal reading.

Stefan
LaTeX.org admin
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Re: Multiple Rows in Table Headers

Post by sw3quant »

Before any adjustments the table comes out looking like the attached file.

This is how I meant it to be viewed with verticle lines seperating the columns. Here you see that the width of the headers in each col is much wider than the width of the data inside the col, hence I wanted to put the headers on more than one row.

I would rather keep things simple for the moment so dont want to implement macros. I have to share the latex with other authors who dont have time to learn about them. Could you be so kind as to explain your solution without macros?

You say "You could use p columns, instead of c, or just p headers." Are you suggesting replacing "c" in "\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}" with "p" ?

thank you
Attachments
latex.jpg
latex.jpg (53.07 KiB) Viewed 29881 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

Multiple Rows in Table Headers

Post by Stefan Kottwitz »

Macros are simple and effective. Just copy the two lines I gave into your document preamble. This already works, later you just write

Code: Select all

& ... \head{1.2cm}{GLOBEX Ticker} & \head{1.5cm}{tickdata.com Ticker} & ...
in your table. That is simple. Without macro, you would have to repeat such \multicolumn expressions for each header.

Stefan
LaTeX.org admin
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Multiple Rows in Table Headers

Post by sw3quant »

ok. added the macro. my code now reads:

Code: Select all

\begin{center}
\captionof{table}{\bf CME GLOBEX Interest Rate Futures.}
\scriptsize
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}
  \hline
\head{0.3cm}{Name} & \head{1.0cm}{GLOBEX Ticker} & \head{1.0cm}{tickdata Ticker} & \head{0.75cm}{Bloomberg Ticker} & \head{1.5cm}{Daily Data Start Date} &\head{0.5cm}{Tick Size} &\head{1.1cm}{Tick Value (\$)}&\head{1.0cm}{Contract Size (\$)}&\head{1.0cm}{Value/ Point}&\head{0.5cm}{Quoting Spec.}&\head{1.3cm}{Int. Margin (\$)}&\head{0.5cm}{ADV (lots)}\\
  \hline \hline
  3M EURO\$ & GE & ED & ED1 Comdty & 01/01/1950 & 0.005      & 12.5 & 1,000,000 & 2,500 & 3 &       1,013     & 2,002,314 \\
  2Yr       & ZT & TU & TU1 Comdty & 01/01/1950 & 0.0078125 & 15.625 & 200,000 & 2,000 & 128ths &   810       & 238,396 \\
  5Yr       & ZF & FV & FV1 Comdty & 01/01/1950 & 0.0078125 & 7.8125 & 100,000 & 1,000 & 128ths &   1,080     & 577,484 \\
  10Yr      & ZN & TY & TY1 Comdty & 01/01/1950 & 0.015625 & 15.625 & 100,000 & 1,000 & 64ths &     1,890     & 1,101,934 \\
  30Yr      & ZB & US & US1 Comdty & 01/01/1950 & 0.03125  & 31.25 & 100,000 & 1,000 & 64ths &      3,375     & 321,724 \\
  \hline
\end{tabular}
\label{irDataTable}
%\vspace{0.1cm}
\end{center}
\normalsize
this gives the PDF image as attached.

I have two questions.

1. You see that the header row no longer has verticle lines at either end. How do I add them back?
2. Some of the text isnt central to the below data (eg see tick size col.)

many thanks for your help!!!
Attachments
latex2.jpg
latex2.jpg (71.1 KiB) Viewed 29879 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

Multiple Rows in Table Headers

Post by Stefan Kottwitz »

You can insert the | for the vertical line in the macro as well, with p{#1}, so the macro definition becomes

Code: Select all

\newcommand{\head}[2]{\multicolumn{1}{>{\centering\arraybackslash}p{#1}|}{\textbf{#2}}}
This makes all "right" vertical lines. One left would be missing still, but it's easily fixed by starting with a normal header, such as:

Code: Select all

\textbf{Name} & \head{1.0cm}{GLOBEX Ticker} & ...
because the normal header already has all lines.

Regarding the centering: the text is centered within the p{Xcm} column, i.e. for the centering it's required to make this cell as wide as the whole column. This brings us back: so it's better to make all as p columns, as earlier said.

Changed macro, new column definition:

Code: Select all

\usepackage{array}
\newcommand{\head}[1]{\textbf{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
...
    \begin{center}
    \captionof{table}{\bfseries CME GLOBEX Interest Rate Futures.}
    \scriptsize
    \begin{tabular}{|C{1.5cm}|C{1.2cm}|C{1cm}|C{1.8cm}|C{1.6cm}|C{1.3cm}|C{1.3cm}|C{1.1cm}|C{1cm}|C{1cm}|C{1.6cm}|C{1.2cm}|}
...
Stefan
LaTeX.org admin
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Multiple Rows in Table Headers

Post by sw3quant »

great. thank you so much! very kind.

My final table is below:

Code: Select all

\begin{center}
\captionof{table}{\bf CME GLOBEX Interest Rate Futures.}
\scriptsize
%\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}
\begin{tabular}{|C{1.3cm}|C{1.0cm}|C{0.75cm}|C{1.5cm}|C{1.3cm}|C{1.0cm}|C{1.1cm}|C{1.0cm}|C{1.0cm}|C{0.5cm}|C{1.3cm}|C{1.0cm}|}
  \hline
\textbf{Name}  & \head{GLOBEX Ticker} & \head{tickdata Ticker} & \head{Bloomberg Ticker} & \head{Daily Data Start Date} &\head{Tick Size} &\head{Tick Value (\$)}&\head{Contract Size (\$)}&\head{Value/ Point}&\head{Quote Spec}&\head{Int Margin (\$)}&\head{ADV (lots)}\\
  \hline \hline
  3M EURO\$ & GE & ED & ED1 Comdty & 01/01/1950 & 0.005      & 12.5 & 1,000,000 & 2,500 & 3 &       1,013     & 2,002,314 \\
  2Yr       & ZT & TU & TU1 Comdty & 01/01/1950 & 0.0078125 & 15.625 & 200,000 & 2,000 & 128ths &   810       & 238,396 \\
  5Yr       & ZF & FV & FV1 Comdty & 01/01/1950 & 0.0078125 & 7.8125 & 100,000 & 1,000 & 128ths &   1,080     & 577,484 \\
  10Yr      & ZN & TY & TY1 Comdty & 01/01/1950 & 0.015625 & 15.625 & 100,000 & 1,000 & 64ths &     1,890     & 1,101,934 \\
  30Yr      & ZB & US & US1 Comdty & 01/01/1950 & 0.03125  & 31.25 & 100,000 & 1,000 & 64ths &      3,375     & 321,724 \\
  \hline
\end{tabular}
\label{irDataTable}
%\vspace{0.1cm}
\end{center}
\normalsize
Post Reply