4

First time using tabularx to create tables, my code is below: (which turns out to be very wrong!)

\begin{table}[htbp]
\caption{\textbf{Description of Regression Variables and Data Sources} \\ This table presents the variable names, definition and data source of the explanatory variables used in Equation~\ref{determinants}. Refer to Table~\ref{tab:sovereignabbreviation} for the abbreviations of the 10 EA sovereigns. Variables 1 to 7 are the local factors and variables 8 to 12 are the regional factors.}
\noindent
\begin{tabularx}{\linewidth}{@{} >{\itshape}lX @{} >{\itshape}lX @{} >{\itshape}lX @{}}\toprule

\multicolumn{1}{c}{} & \multicolumn{1}{c}{\textbf{Variable}} & \multicolumn{1}{c}{\textbf{Description}} & \multicolumn{1}{c}{\textbf{Data Source}} \\ \midrule
1 &        Average probability of default (PoD)          &  Bootstrapped sovereign PoD & Own calculation\\
2 & Standard deviation of PoD            & The standard deviation of the sovereign bootstrapped PoDs computed at each point in time & Own calculation \\
3 & Stock market returns           & Daily stock market returns of the main stock market indices of each sovereign & Datastream \\
4 & Volatility of stock market returns          & Volatility of main stock market returns of each sovereign with a rolling window of 6 months & Datastream\\
5 & Total reserves to debt ratio         & Total reserves excluding gold/government debt & Bloomberg\\
6 & GDP          & Natural log of GDP & Bloomberg \\
7 & Debt to GDP        & Government debt/GDP & Bloomberg \\
8 & Average correlation between changes in CDS Spreads         & Average pairwise correlation with a rolling window of 1 year & Own calculation \\
9 & Standard deviation of changes in CDS spread correlation           & Standard deviation of the average correlation between changes in CDS Spreads computed at each point in time & Own calculation\\
10 & Trade flows          & Sum of imports and exports/GDP & Bloomberg\\
11 & Regional implied volatility          & VSTOXX Index & Datastream\\
12 & Term spread        & Difference between 10-year and the 3-month EA AAA-bond yields & Datastream \\\bottomrule


\end{tabularx}%
\label{variables}
\end{table}%

I wish to create a table that looks like this: (Doesn't necessarily need the grid lines)

enter image description here

How can I do so?

3 Answers 3

5

Please always post complete documents showing all packages used.

You had fragile commands in the caption, which I avoided by supplying a short caption for the list of tables, and in the tabularx you had specified far more columns than your data used.

enter image description here

\documentclass{article}
\usepackage{tabularx,booktabs}

\begin{document}
\begin{table}[htbp]
\caption[Description of Regression Variables and Data Sources]{Description of Regression Variables and Data Sources\\
This table presents the variable names, definition and data source of the explanatory variables used in Equation~\ref{determinants}. Refer to Table~\ref{tab:sovereignabbreviation} for the abbreviations of the 10 EA sovereigns. Variables 1 to 7 are the local factors and variables 8 to 12 are the regional factors.}

\noindent
\begin{tabularx}{\linewidth}{@{}l>{\raggedright}X>{\raggedright}Xl@{}}\toprule

\multicolumn{1}{c}{} & \multicolumn{1}{c}{\textbf{Variable}} & \multicolumn{1}{c}{\textbf{Description}} & \multicolumn{1}{c}{\textbf{Data Source}} \\ \midrule
1 &        Average probability of default (PoD)          &  Bootstrapped sovereign PoD & Own calculation\\
2 & Standard deviation of PoD            & The standard deviation of the sovereign bootstrapped PoDs computed at each point in time & Own calculation \\
3 & Stock market returns           & Daily stock market returns of the main stock market indices of each sovereign & Datastream \\
4 & Volatility of stock market returns          & Volatility of main stock market returns of each sovereign with a rolling window of 6 months & Datastream\\
5 & Total reserves to debt ratio         & Total reserves excluding gold/government debt & Bloomberg\\
6 & GDP          & Natural log of GDP & Bloomberg \\
7 & Debt to GDP        & Government debt/GDP & Bloomberg \\
8 & Average correlation between changes in CDS Spreads         & Average pairwise correlation with a rolling window of 1 year & Own calculation \\
9 & Standard deviation of changes in CDS spread correlation           & Standard deviation of the average correlation between changes in CDS Spreads computed at each point in time & Own calculation\\
10 & Trade flows          & Sum of imports and exports/GDP & Bloomberg\\
11 & Regional implied volatility          & VSTOXX Index & Datastream\\
12 & Term spread        & Difference between 10-year and the 3-month EA AAA-bond yields & Datastream \\\bottomrule
\end{tabularx}%
\label{variables}
\end{table}%

\end{document}
4
  • Thanks, could you elaborate on @{}l>{\raggedright}X>{\raggedright}Xl@{} ? I'm not sure how to add columns in tabularx environment.
    – TrueTears
    Commented May 19, 2013 at 12:56
  • 2
    The only additional change I'd suggest is to load the ragged2e package and to use >{\RaggedRight}X as the specifier for the two middle columns. This will allow hyphenation of words to be performed.
    – Mico
    Commented May 19, 2013 at 12:57
  • 1
    @TrueTears tabularx syntax is exactly the same as (array package) tabular syntax with the addtion of X which is p{some length so you have 4 columns lXXl but you want the two X columns to be ragged not justified so >{\raggedright}X or >{\RaggedRight}X as suggested in the comments where \RaggedRight is a perhaps better raggedright macro than the standard one. Commented May 19, 2013 at 13:16
  • 2
    @David Carlisle Thanks, how about @{} ? What is that used for?
    – TrueTears
    Commented May 19, 2013 at 13:22
3

Remarks for the example below:

  • Package raggedright provides \RaggedRight that is similar to \raggedright, but allows hyphenation to get a smoother right margin, especially for narrow columns.

  • >{\itspape}lX: Your example image does not contain italics. Also this are two columns, a left-aligned column and an extensible column that allows several lines. The example images contains one ragged-right column instead.

  • With some trickery via \hsize the width of the X-columns can be adjusted, the column "Description" contains more text, thus I have made the column wider. See the examples in the documentation of tabularx.

  • l seems to be enough for the third column.

  • Also I have added some indentation of the followup lines in the table cells. Perhaps it makes the tabular rows more clear and easier to read.

  • The caption I have formatted via package caption. Instead of the caption text I have made the caption label bold, because I think it is more common, if something is made bold in the caption. Your version would be the commented line above. Also both can be made bold (combine both options labelfont and textfont).

  • Since one-line captions are centered by default, I have added option singlelinecheck.

  • IMHO the legend does not belong to the caption, therefore I have moved the explanation text outside the caption. Otherwise the optional argument of \caption should be used to prevent that the legend appears in the list of tables.

Example:

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{ragged2e}
\usepackage{caption}
\newcommand*{\xformat}{%
  \RaggedRight
  \setlength{\hangindent}{1em}%
  \hangafter=1\relax
}

%\captionsetup{textfont+=bf, singlelinecheck=false}
\captionsetup{labelfont+=bf, singlelinecheck=false}

\begin{document}
\begin{table}[htbp]
\caption{Description of Regression Variables and Data Sources}

This table presents the variable names, definition and data source of the
explanatory variables used in Equation~\ref{determinants}.  Refer to
Table~\ref{tab:sovereignabbreviation} for the abbreviations of the 10 EA
sovereigns.  Variables 1 to 7 are the local factors and variables 8 to 12
are the regional factors.

\medskip
\noindent
\begin{tabularx}{\linewidth}%
  {r >{\xformat\hsize=.75\hsize}X >{\xformat\hsize=1.25\hsize}X l}
\toprule
\multicolumn{1}{c}{} & \multicolumn{1}{c}{\textbf{Variable}} & \multicolumn{1}{c}{\textbf{Description}} & \multicolumn{1}{c}{\textbf{Data Source}} \\
\midrule
1 &        Average probability of default (PoD)          &  Bootstrapped sovereign PoD & Own calculation\\
2 & Standard deviation of PoD            & The standard deviation of the sovereign bootstrapped PoDs computed at each point in time & Own calculation \\
3 & Stock market returns           & Daily stock market returns of the main stock market indices of each sovereign & Datastream \\
4 & Volatility of stock market returns          & Volatility of main stock market returns of each sovereign with a rolling window of 6 months & Datastream\\
5 & Total reserves to debt ratio         & Total reserves excluding gold/government debt & Bloomberg\\
6 & GDP          & Natural log of GDP & Bloomberg \\
7 & Debt to GDP        & Government debt/GDP & Bloomberg \\
8 & Average correlation between changes in CDS Spreads         & Average pairwise correlation with a rolling window of 1 year & Own calculation \\
9 & Standard deviation of changes in CDS spread correlation           & Standard deviation of the average correlation between changes in CDS Spreads computed at each point in time & Own calculation\\
10 & Trade flows          & Sum of imports and exports/GDP & Bloomberg\\
11 & Regional implied volatility          & VSTOXX Index & Datastream\\
12 & Term spread        & Difference between 10-year and the 3-month EA AAA-bond yields & Datastream \\
\bottomrule
\end{tabularx}%
\label{variables}
\end{table}
\end{document}

Result

1
[...]
\usepackage{tabularx,booktabs,ragged2e}
[...]

\begingroup
\noindent\tabcolsep=3pt
\begin{tabularx}{\linewidth}{@{}r>{\RaggedRight}X>{\RaggedRight}Xl @{}}\toprule
[...]
\end{tabularx}
\endgroup
[...]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .